what am i doing wrong

T

thatsme

I'm trying to access static data member through static function. Here is the
source

class Something
{
private:
static int s_nValue;
public:
static int GetValue() { return s_nValue; }
};
int Something::s_nValue = 1;


#include <iostream>
#include "Something.h"
int main()
{
std::cout << Something::GetValue() << std::endl;
return 0;
}


I'm using MS Visual studio and I keep getting these errors:

error LNK2019: unresolved external symbol _WinMain@16 referenced in function
___tmainCRTStartup MSVCRTD.lib test
fatal error LNK1120: 1 unresolved externals C:\***
 
V

Victor Bazarov

I'm trying to access static data member through static function. Here is the
source

class Something
{
private:
static int s_nValue;
public:
static int GetValue() { return s_nValue; }
};
int Something::s_nValue = 1;


#include<iostream>
#include "Something.h"
int main()
{
std::cout<< Something::GetValue()<< std::endl;
return 0;
}


I'm using MS Visual studio and I keep getting these errors:

error LNK2019: unresolved external symbol _WinMain@16 referenced in function
___tmainCRTStartup MSVCRTD.lib test
fatal error LNK1120: 1 unresolved externals C:\***

This is unrelated to your language abilities. You're building your
program as a "Windows" executable. Switch to building a "Console"
executable. These things are specific to programming Windows, not C++.

If you want to learn more about the differences between different
"targets" under your OS of choice (or chance), find a decent book or do
lots of searches in your help system. Also, take up the habit of
looking on the Web first before asking in a newsgroup.

V
 
R

red floyd

I'm trying to access static data member through static function. Here is the
source

class Something
{
private:
static int s_nValue;
public:
static int GetValue() { return s_nValue; }};

int Something::s_nValue = 1;

#include <iostream>
#include "Something.h"
int main()
{
std::cout << Something::GetValue() << std::endl;
return 0;

}

I'm using MS Visual studio and I keep getting these errors:

error LNK2019: unresolved external symbol _WinMain@16 referenced in function
___tmainCRTStartup MSVCRTD.lib test

In addition to what Victor said, you also haven't defined
Something::s_nValue.

Please see FAQ 10.2

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top