0

When I run this basic code I get the error LINK2019 and it says:

Error LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) clickerNew c:\Users\john mcpenis\documents\visual studio 2017\Projects\clickerNew\clickerNew\MSVCRTD.lib(exe_winmain.obj) 1

I'm guessing I've missed something basic or done something stupid. Any help on this would be much appreciated.

#include <iostream>

using namespace std;

class clicker
{
private:
    int counter;

public:
    clicker(int c = 0) :
            counter(c)
    {
    }
    void click();
    void reset();
    void display();
};

void clicker::click()
{
    counter++;
}

void clicker::reset()
{
    counter = 0;
}

void clicker::display()
{
    cout << counter << endl;
}

int main()
{
    clicker c;
    c.click();
    c.click();
    c.click();
    c.display();
    c.reset();
    c.display();
    c.click();
    c.display();

    return 0;
}
Tas
  • 7,023
  • 3
  • 36
  • 51
Tentacles
  • 57
  • 1
  • 9
  • Where is your `main` function? – Jiahao Cai Jul 26 '17 at 02:26
  • Because you haven't used main function. program run starts from main – Preet Jul 26 '17 at 02:28
  • Ah, my apologies I have a main function I just got the same error even when I removed it so I didn't think that would be the problem. I have now added in my main function. – Tentacles Jul 26 '17 at 02:29
  • try void main instead as you returning 0 – Preet Jul 26 '17 at 02:30
  • 3
    @Preet: `main` is *supposed* to return an `int`. – Scott Hunter Jul 26 '17 at 02:35
  • I didn't think you could even compile `void main` programs in the current compilers. – Cory Madden Jul 26 '17 at 02:40
  • I agree @Scott Hunter. He can try removing return 0; line as it will automatically assumed by compiler – Preet Jul 26 '17 at 02:41
  • @CoryMadden I think Visual Studio is one of the last, and mostly due to reams of ancient wrong code. – user4581301 Jul 26 '17 at 02:41
  • @user4581301 ah, that makes sense. I had a conversation with a C++ instructor somewhat recently that didn't know. She probably uses VS – Cory Madden Jul 26 '17 at 02:45
  • 2
    Are you compiling as a console application (`/SUBSYSTEM:CONSOLE`)? It looks like you're trying to compile a Windows app – Tas Jul 26 '17 at 02:49
  • 1
    Possible dupe: https://stackoverflow.com/questions/33400777/error-lnk2019-unresolved-external-symbol-main-referenced-in-function-int-cde?rq=1 or https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16 – Tas Jul 26 '17 at 02:51
  • Thank you, after updating my program switched program modes with out me noticing. – Tentacles Jul 26 '17 at 02:54

0 Answers0