this is my class definition:
#include <iostream>
using namespace std;
class Math
{
private:
static int result;
public:
static int add( int a , int b)
{
result = a + b ;
return result;
};
};
this is the main:
#include <iostream>
#include "Amin.cpp"
using namespace std;
int main()
{
Math::add(2,3);
}
and i got these errors in visual studio:
error LNK2001: unresolved external symbol "private: static int Math::result" error LNK1120: 1 unresolved externals
best regards
Just add
int Math::result;
in your cpp
file.
Math::result
is declared as a static
data variable in the definition of Math
and should be defined somewhere. This can be the cpp
file containing main()
or any other to be found by the linker. You need not and should not repeat the keyword static
at the definition.
By the way, you should avoid using namespace std;
(or any other namespace) in a header file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With