Jump to content
  • Advertisement
Sign in to follow this  
hannes100

static methods in c++ (makefile)

This topic is 4778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Can you post an example of the code that is producing the linker error?

*edit* - Nevermind. That doesn't help you.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!