它不会在 Visual Studio 中编译,它说
1>MSVCRTD.lib(crtexe.obj):错误 LNK2019:函数 ___tmainCRTStartup 中引用的未解析外部符号 _main
1>position.exe: fatal error LNK1120:1 个 Unresolved external 问题
#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;
}
最佳答案
它是在 Visual Studio Professional 2008 下为我编译的。
尝试创建一个新项目。
选择文件->新建并指定项目类型为 Visual C++ -> Win32 -> Win32 控制台应用程序。
然后点击确定。
然后单击“应用程序设置”并取消选中“预编译 header ”。
然后粘贴你的代码,编译成功。
关于C++ 这个类有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7642021/