link error

Discussion in 'C++' started by wenqiang.zhou, May 22, 2006.

  1. ************************************************
    #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
    wenqiang.zhou, May 22, 2006
    #1
    1. Advertising

  2. wenqiang.zhou

    Ian Collins Guest

    wenqiang.zhou wrote:
    > 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.

    --
    Ian Collins.
    Ian Collins, May 22, 2006
    #2
    1. Advertising

  3. wenqiang.zhou

    Marcus Kwok Guest

    wenqiang.zhou <> wrote:
    > ************************************************
    > #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.

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
    Marcus Kwok, May 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    800
    Kevin Spencer
    May 17, 2005
  2. Graham Thomson
    Replies:
    3
    Views:
    445
    Eki Y. Baskoro
    Dec 18, 2003
  3. Dan M
    Replies:
    5
    Views:
    412
  4. kolesdz
    Replies:
    9
    Views:
    519
    Blinky the Shark
    Aug 22, 2007
  5. Marina Limeira

    LINK with another link

    Marina Limeira, Feb 7, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    106
    Marina Limeira
    Feb 7, 2006
Loading...

Share This Page