link error

W

wenqiang.zhou

************************************************
#include <iostream>
#include <string>
using namespace std;

class Shape
{
public:
Shape(void) {}
~Shape(void) {}
virtual void draw(void) const { cout<<"Shape draw"<<endl; }
};

class Rectangle : public Shape
{
public:
Rectangle(void) {}
~Rectangle(void) {}
void draw(void) const { cout<<"Rectangle draw"<<endl; }
};

class Ellipse : public Shape
{
public:
Ellipse(void) {}
~Ellipse(void) {}
};

int _tmain(int argc, char* argv[])
{
Shape *pr = new Rectangle;
pr->draw();
pr->Shape::draw();
delete pr;
pr = NULL;

Shape *pe = new Ellipse;
pe->draw();
delete pe;
pe = NULL;

return 0;
}

--------------------Configuration: virturnl - Win32
Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/virturnl.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

virturnl.exe - 2 error(s), 0 warning(s)

************************************************
My IDE tool is VC++6.0 , when i want to build the code, the errors will
display when it linked. but i have never meet the error , have anyone known
whats wrong with it and give me an advice , thanks
 
I

Ian Collins

wenqiang.zhou said:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/virturnl.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

virturnl.exe - 2 error(s), 0 warning(s)
A C++ program must have a main() function, yours does not, hence the error.
 
M

Marcus Kwok

wenqiang.zhou said:
************************************************
#include <iostream>
#include <string>
using namespace std;

class Shape
{
public:
Shape(void) {}
~Shape(void) {}

Your destructor should be virtual, since in _tmain() you are deleting a
derived class through a base class pointer.
virtual void draw(void) const { cout<<"Shape draw"<<endl; }
};

class Rectangle : public Shape
{
public:
Rectangle(void) {}
~Rectangle(void) {}
void draw(void) const { cout<<"Rectangle draw"<<endl; }
};

class Ellipse : public Shape
{
public:
Ellipse(void) {}
~Ellipse(void) {}
};

int _tmain(int argc, char* argv[])

Non-standard. Try:

int main(int argc, char* argv[])

or since you are not using any command line arguments:

int main()
{
Shape *pr = new Rectangle;
pr->draw();
pr->Shape::draw();
delete pr;
pr = NULL;

Shape *pe = new Ellipse;
pe->draw();
delete pe;
pe = NULL;

return 0;
}

--------------------Configuration: virturnl - Win32
Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

See above, maybe VC++6.0 doesn't like _tmain instead of main.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top