473,545 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linker Error: Unresolved external symbol

14 New Member
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 4077
AceKnocks
14 New Member
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 Recognized Expert Moderator Expert
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
AceKnocks
14 New Member
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 Recognized Expert Moderator Expert
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
1679
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, I compiled the Python Extensions, but am getting the following error:
0
1443
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? Linking... atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol ___security_cookie PenPacketInfoDlg.obj : error LNK2019: unresolved...
1
1909
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 _IID_IFileSinkFilter cvision error LNK2001: unresolved external symbol _IID_ICreateDevEnu cvision error LNK2001: unresolved external symbol _IID_IBaseFilte...
4
1807
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 teh spaces in my solution directory, I get the following errors: MastController.exp : error LNK2001: unresolved external symbol _Calibrate@8...
3
8103
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) : error LNK2001: unresolved external symbol ___argc nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
3
8048
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 LNK2028: unresolved token (0A000007) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)"...
0
1744
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 one of the libraries that the project uses. Without the /CLR, the project compiles and runs well. There is some library by name task.lib and the...
1
3273
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, but throws a load of linker errors
1
10344
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 working in the release mode. I mean it is shooting off linking errors. I am required to generate an exe file and am looking for some suggestions!!!...
2
1416
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 makes the .lib. I change the project to a Dynamic Linked Library (.dll), and then try to compile and it makes all the .obj files, but fails with...
0
7420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.