Jump to content
  • Advertisement
Sign in to follow this  
xinvar

[solved] C++ static member error: error LNK2001: unresolved external symbol

This topic is 4865 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, I have a C++ class that includes some static members: class COpenGL_Window : public CView { protected: COpenGL_Window(); // protected constructor used by dynamic creation DECLARE_DYNCREATE(COpenGL_Window) static bool m_bHRCValid; } I use bHRCValid in OpenGL_Window.cpp. But when I try to compile the project, it gave the following error: error LNK2001: unresolved external symbol "public: static bool COpenGL_Window::m_bHRCValid" (?m_bHRCValid@COpenGL_Window@@2_NA) Also ifI use COpenGL_Window::m_bHRCValid = false; at the beginning of OpenGL_Window.cpp, the compiler says it cannot recoganize this. Is it related to DECLARE_DYNCREATE? I would appreciate any help. [Edited by - xinvar on July 21, 2005 6:38:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
You never implement the function COpenGL_Window();

somewhere (in your cpp file most likely) there should be something that looks like:


COpenGL_Window::COpenGL_Window()
: m_bHRCValid(false) //this line will initialize the member var
{
//whatever's supposed to happen in the constructor
}










you can only do things like this:

COpenGL_Window::m_bHRCValid = false

if the member variable is declared static. static in this usage basically means basically a single variable that is shared between all class instances. This does not seem like what you want.

I'd suggest that you find a good C++ tutorial or book and work your way thhrough it before mucking around with openGL.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by xinvar
Also ifI use COpenGL_Window::m_bHRCValid = false; at the beginning of OpenGL_Window.cpp, the compiler says it cannot recoganize this.



bool COpenGL_Window::m_bHRCValid = false;

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
You never implement the function COpenGL_Window();


Palidine, I did implement the constructor.

Verg, thanks a lot, that worked!

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
if the member variable is declared static. static in this usage basically means basically a single variable that is shared between all class instances. This does not seem like what you want.


That is what I want. I wanted all rendering contexts to share the same texture objects.

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!