Solved

Static members with VC++ 5.0

Posted on 1998-07-17
5
269 Views
Last Modified: 2013-11-20
I'm using VC++ 5.0 and I have static members in a class that I wrote.
I'm trying to assign values to them from the outside, but I get an error that looks like this:

ipserialDlg.obj : error LNK2001: unresolved external symbol "public: static int  CMyDataSocket::m_ReadState" (?m_ReadState@CMyDataSocket@@2HA)
MyDataSocket.obj : error LNK2001: unresolved external symbol "public: static int  CMyDataSocket::m_ReadState" (?m_ReadState@CMyDataSocket@@2HA)

m_ReadState is the member, and it was declared like this:
static BOOL m_ReadState;

ipserialDlg is the program that's trying to set the variables, with code that looks like this:
CMyDataSocket::mReadState=TRUE;

Any ideas?  I am using bad syntax?
0
Comment
Question by:awong726
  • 3
5 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1319389
The LNK2001 error is usually occurred when the file containing the sympol is not included in the file using the symbol. Check to see whether you include the file containing the class CMyDataSocket.
0
 

Author Comment

by:awong726
ID: 1319390
Yup.  It's included and I'm still getting the error.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319391
The LNK2001 error is usually occurred when the file containing the sympol is not included in the file using the symbol. Check to see whether you include the file containing the class CMyDataSocket.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319392
I think use extern m_ReadState; BOOL m_ReadState=TRUE; at the begining of your file can correct this error.
0
 

Accepted Solution

by:
zingo earned 20 total points
ID: 1319393
Have you initialized your static variable? If not, write a statement like this:

BOOL CMyDataSocket::m_ReadState = TRUE;

at the beginning of the MyDataSocket.cpp file.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question