Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: ERROR: identifier "getTransform" is undefined  (Read 2353 times)

0 Members and 2 Guests are viewing this topic.

hal1001

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
ERROR: identifier "getTransform" is undefined
« on: December 28, 2013, 05:54:25 am »
I apologize as I'm coming from the Java world and trying to learn C++ while using SFML as my motivation, so this will probably come across as very novice:

LevelOne.hpp

#ifndef LEVEL_ONE_H
#define LEVEL_ONE_H

#include <SFML/Graphics.hpp>

class LevelOne : public sf::Drawable, public sf::Transformable
{
public:
        LevelOne();
        ~LevelOne();
};

#endif
 

LevelOne.cpp

#include "LevelOne.hpp"

LevelOne::LevelOne()
{
}

LevelOne::~LevelOne()
{
}

void draw(sf::RenderTarget& target, sf::RenderStates states)
{
        sf::VertexArray vertices;
        sf::Texture texture;

        states.transform *= getTransform();
        states.texture = &texture;
        target.draw(vertices, states);
}
 

For getTransform() I get ERROR: identifier "getTransform" is undefined. If I don't use a header file, and just simply have a class declaration then it finds the method.

Thanks for the help.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: ERROR: identifier "getTransform" is undefined
« Reply #1 on: December 28, 2013, 06:27:20 am »
Your draw function is a free function, it should be a member function of LevelOne.
//hpp
class LevelOne : public sf::Drawable, public sf::Transformable
{
public:
    LevelOne();
    ~LevelOne();
    void draw(sf::RenderTarget& target, sf::RenderStates states);
};

//cpp
void LevelOne::draw(sf::RenderTarget& target, sf::RenderStates states)
{
    ...

BTW, you need to know C++ to use SFML.

Same time Nexus. :D

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: ERROR: identifier "getTransform" is undefined
« Reply #2 on: December 28, 2013, 06:27:20 am »
draw() has to be a member function:
void LevelOne::draw(sf::RenderTarget& target, sf::RenderStates states)
//   ^^^^^^^^^^

By the way, if you really want to learn C++, you can't just do that by using SFML. Even if the language looks similar to Java, there are substantial differences which are important to know. I therefore recommend to read a good C++ book in advance.

G., the very same second!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

hal1001

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: ERROR: identifier "getTransform" is undefined
« Reply #3 on: December 28, 2013, 05:05:12 pm »
Thanks Nexus and G., that worked!

I'm definitely going through the motions to learn C++. Accelerated C++: Practical Programming by Example is in the mail, and I've been walking through learncpp.com. I had a game I was making using Java 2D, and the API just wasn't intended for that purpose. So I was going to try out JSFML, but decided this was a good opportunity to finally pick up C++.

Thanks again for the help.