473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Linker Error: Unresolved external symbol

Hi all,
I have these two classes with following structure

Expand|Select|Wrap|Line Numbers
  1. //main.cpp
  2.  
  3. class Tree {
  4. public:
  5. static bool flag;
  6. Tree() { 
  7. flag = true;
  8. }
  9. };
  10.  
  11. class b {
  12. public:
  13. static bool isValid();
  14. };
  15.  
  16. static isValid() {
  17. if (Tree::flag) ... some code
  18. }
  19.  
When compiling the above code, there were no errors. However, upon linking I get the following error
error LNK2001: unresolved external symbol "public: static bool Tree::flag" (?flag@Tree@@2_NA)
fatal error LNK1120: 1 unresolved externals

What am I doing wrong here?
Jan 5 '08 #1
4 4067
Just got to know that if we need to access a static data member from a class within a file scope, we need to define it after class declaration.

http://msdn2.microsoft.com/en-us/library/b1b5y48f(VS.80).aspx

Resolved! :)
Jan 5 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
That's because the static variable is not part of any object. Therefore, when is it created?? The answer is that you need to create it yourself as a static variable.

That said, why is the variable static in the first place. On sht surface this does ot appear to be a situation where a static variable should be used.

I try to avoid static variables due to problems you get into with multi-threaded programs where more than one thread can access the sam variable. I see static anything as warning that bad code follows.
Jan 6 '08 #3
Yep, I do agree on that but here I class B has to count instances of the class A's objects created at any given point in time.
Jan 6 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Yep, I do agree on that but here I class B has to count instances of the class A's objects created at any given point in time.
Check out the Observer design pattern.

You don't need a static variable to do this.

However, if you use one, you have to create it manually.
Jan 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim | last post by:
All, I'm trying to debug a Python GPF while running a script that we've written. After fixing up some of the paths for the Python build and successfully building Python from ActiveState source,...
0
by: KS | last post by:
I am getting linker error for a code that was tested and running. I opened the project in VS.NET 2003 and now i get these errors - I am sure it is some options issue. Can anyone please help? ...
1
by: endo55 | last post by:
Hi I've got the following errors when trying to compile a program cvision error LNK2001: unresolved external symbol _IID_IGraphBuilde cvision error LNK2001: unresolved external symbo...
4
by: Joel Whitehouse | last post by:
Hello All, I have a Visual C++ 2003 dll solution in a directory called "Antenna Test Range Control", and when I comile it, I get the error LNK1104: cannot open file "antenna.obj". When I remove...
3
by: ac2806 | last post by:
Hi I want to use the static MFC within a dll, but I get the following errors when linking: nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcwd.lib(appcore.obj)...
3
by: Chucker | last post by:
Hi Folks, I got a Wrapper Dll around a native C++ static library. In .NET 1.1 this worked fine. When moving to .NET 2.0 I get a couple of unresolved externals / linker errors: Error 16 error...
0
by: VivekR | last post by:
I have a MFC application developed using VC++ 5. Recently I ported that to VC++ 7.1 and now I am trying to compile the MFC application with /CLR under VC++ 7.1. And I get linker errors referring to...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
1
by: iiitsunny | last post by:
i have ported one project which was working in VC6 to VC7. Now the project is working fine in VC7 also. I have made some additions in VC7 environment only. But the problem is that the project is not...
2
by: NvrBst | last post by:
I have C99 code (which I changed extensions to .cpp to compile as C+ +98). Which is does fine. I create a Static Library Project (.lib) and Build, and it builds the .obj files (9 of them) and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.