Sign in to follow this  
hannes100

static methods in c++ (makefile)

Recommended Posts

Hi, if i wrote C/C&& Programs (on Linux Plaforms), i allways used some "just copy-paste-compile it-somehow" makefiles, i.e. i never spended much time to really understand makefiles. And exactly at this point my problem starts. the simplifyed example of my problem is the following: i have a class, where i want to use static methods of another class...I allways only get linker errors.(so i think i define them right) If i make it non static it all works. Thanx for any help :-)

Share this post


Link to post
Share on other sites
You havn't really posted enough information, so I'll have to take a guess:

If you have put the keyword static in your .cpp file (on your function) - remove it - it only needs to be in the .h file in the class definition.

Share this post


Link to post
Share on other sites
her some simplifeyed code :

//PhysikEngine.h
class PhysicEngine
{
public:
PhysicEngine();
virtual ~PhysicEngine();
static void doNothing();
.
.
.


//PhysicEngine.cpp

#include "PhysicalObject.h"
#include "PhysicEngine.h"

PhysicEngine::PhysicEngine()
{
}

PhysicEngine::~PhysicEngine()
{
}
void PhysicEngine::doNothing() {
}
.
.
.

//OpenGl class where i want to use it
void init(void)
{
PhysicEngine.doNothing();
axis.setvalue(0,0);
axis.setvalue(1,1);
axis.setvalue(2,0);
GLfloat mat_specular[] = { 1.0, 1.0,


//Makefile
RM = /bin/rm -f

C++ = g++
CCFLAGS = -I. -I/usr/X11R6/include -L/usr/X11R6/lib --verbose

LDFLAGS = -lpthread -lglut -lGLU -lGL -lm -lXi -lX11 -lXmu -lXext

clean:
@echo --- $@ ---
-$(RM) *.o core

all: PhysicEngine.h PhysicEngine.o PhysicalObject.o PointMass.o SMatrix.o Vektor.o
@echo --- $@ ---
$(C++) $(CCFLAGS) GameEngine.cc Vektor.o SMatrix.o PhysicEngine.o PhysicalObject.o PointMass.o -o GameEngine $(LDFLAGS)

Vektor.o: Vektor.cc Vektor.h
$(C++) -c $(CCFLAGS) -o Vektor.o Vektor.cc $(LDFLAGS)

SMatrix.o: SMatrix.cc SMatrix.h
$(C++) -c $(CCFLAGS) -o SMatrix.o SMatrix.cc $(LDFLAGS)

PhysicEngine.o : PhysicEngine.cpp PhysicalObject.h
$(C++) -c $(CCFLAGS) -o PhysicEngine.o PhysicEngine.cpp $(LDFLAGS)

PhysicalObject.o : PhysicalObject.cpp PointMass.h
$(C++) -c $(CCFLAGS) -o PhysicalObject.o PhysicalObject.cpp $(LDFLAGS)

PointMass.o : PointMass.cpp SMatrix.h
$(C++) -c $(CCFLAGS) -o PointMass.o PointMass.cpp $(LDFLAGS)



i removed the static in the .cpp file :
now i get the following error message :
GameEngine.cc: In function `void init()':
GameEngine.cc:22: error: parse error before `.' token
make: *** [all] Error 1

if i do it like this :
PhysicEngine e;
e.doNothing();
it works.

Share this post


Link to post
Share on other sites
To call a static member function you should use two colons instead of one dot:

PhysicEngine::doNothing();


Greetz,

Illco

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this