C ++这门课有什么问题?

时间:2011-10-04 00:06:32

标签: c++ debugging class

它不能在Visual Studio中编译,它说

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

#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;
}

2 个答案:

答案 0 :(得分:1)

它是在Visual Studio Professional 2008下为我编译的。

尝试创建新项目。

选择文件 - &gt;新建并指定Visual C ++的项目类型 - &gt; Win32 - &gt; Win32控制台应用程序。

然后单击“确定”。

然后单击“应用程序设置”并取消选中“预编译标题”。

然后粘贴代码并成功编译。

答案 1 :(得分:1)

确保您正在创建一个空项目或Win32 控制台应用程序。如果您创建了Win32 Windows 应用程序,那么您将收到此错误。

相关问题