开发者

C++ What's wrong with this class?

It doesn't compile in Visual Studio, it says

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

1>position.exe : fatal error LNK1120: 1 unresolved ex开发者_StackOverflow中文版ternals

#include <iostream>
#include <cstdlib>

using namespace std;

class Position
{
private:
    int row;
    int column;
public:
    Position();         //constructor
    ~Position();        //destructor
    void setPos(int, int);  //set the position
    int getRow();       //return the current row
    int getColumn();    //return the current column
    void getPos();      //print the pos
    bool compare(int, int); //compare a row and column with the one in the class
};

Position::Position()
{}
Position::~Position()
{}
void Position::setPos(int x, int y)
{
    row = x;
    column = y;
}
int Position::getRow()
{
    return row;
}
int Position::getColumn()
{
    return column;
}
void Position::getPos()
{
    cout << "Row: " << row << "Column: " << column;
}
bool Position::compare(int x, int y)
{
    if(x == row && y == column)
        return true;
    else
        return false;
}

int main()
{
    return 0;
}


It compiled for me under Visual Studio Professional 2008.

Try creating a new project.

Select File->New and specify Project Type of Visual C++ -> Win32 -> Win32 Console Application.

Then click Ok.

Then click on Application Settings and uncheck "Precompiled header".

Then paste in your code and compile it successfully.


Make sure you're creating an empty project or a Win32 console application. If you make a Win32 Windows application then you will get this error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜