I am an experienced Java programmer and now I've been asked to do some C++ which has not been so bad in Linux. However, I have to move now to Visual Studio 2010. I am just trying to create a simple console program, and add a couple of classes. I do that with all the default settings, just pick a Win32 Console application at first, I have tried with both the pre-compiled header and an empty project. I add a simple class that does this:
Header:
1 2 3 4 5 6 7 8 9 10 11 12
#pragma once
class TestClass
{
public:
TestClass(void);
~TestClass(void);
staticdouble mapZeroToMax(double toMap, double max);
staticdouble linearScale(double x, double a, double b);
};
And it never compiles and gives me the following errors:
Error 1 error LNK2019: unresolved external symbol "public: static double __cdecl TestClass::mapZeroToMax(double,double)" (?mapZeroToMax@TestClass@@SANNN@Z) referenced in function _main...
Error 2 error LNK1120: 1 unresolved externals
I did several google searches and found things like "change the linker to Windows app instead of a Console App"... and so on. None of that has worked. Any ideas how to pass this error?
Thanks!
LNK2019 errors were the bane of my existence during the initial part of my internship, so I can sympathize with you.
I think the linker error is being caused by your methods mapZeroToMax(...) and linearScale(...) methods not being within TestClass's scope.
You should change the definitions in your cpp file to prefixed with TestClass:: as you have done for your default constructor and destructor. For example: