• Advertisement
Sign in to follow this  

static class members

This topic is 2406 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

Okay so im making a game and i have to manage texture references that are returned from opengl when i load textures.

HOW THE MANAGER WORKS:

The manager is only has static members so i can access them anywhere.
The manager works by associating a texture reference with the a keyword generated from the path of the image.
for example,lets say i load an image from C:/blah/blah/image.png
the Manager will generate the keyword : IMAGE.PNG
If the keyword already exists, the texture has already been loaded and then it searches for the texture reference.
If the keyword doesnt exist then the manager will load the texture and assign the keyword to that texture.

MY PROBLEM:
The main problem is that i when i call the static public procedures i cant interact with the static private members of the class ,
It wont compile because the compiler gives the error :"UNDEFINED REFERENCE".

Example:

#include <iostream>
#include <string>
class Manager{
public:
static void SET_PATH(std::string INIT_PATH){
PATH = INIT_PATH;
}
static std::string GET_PATH(){
return PATH;
}
private:
static std::string PATH;
};

int main(){
std::string TEST_PATH("C:/TEST");

Manager::SET_PATH(TEST_PATH);//Undifined reference to 'Manager::PATH'

return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
When you create a static member variable in a class you only have a declaration for the variable. In order for your program to link you also need to add a definition for the variable. In once source file in the same namespace as the class you need to add a line that looks like:

std::string Manager::PATH;

Share this post


Link to post
Share on other sites
Hidden

When you create a static member variable in a class you only have a declaration for the variable. In order for your program to link you also need to add a definition for the variable. In once source file in the same namespace as the class you need to add a line that looks like:

std::string Manager::PATH;

can i define and declare in the class?
I kinda wanted all the code to be in one header so all i have to do is call the static functions and the rest is taken care of by the static sub procedures written in the header

Share this post


Link to post
Only with constant integral types. It sucks but that's the way it is.

Use C#

Share this post


Link to post
Share on other sites
Why is deleting of posts allowed?

It's strange to answer a question that disappears.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement