C++ 这个类有什么问题?

标签 c++ debugging class

它不会在 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/

相关文章:

java - Java 中按位运算的调试工具

java - 如何使我的方法接受 x 个参数

c++ - 什么是 C++ GSL 指南?

可由文件控制的C调试器

c++ - 如何现代化 VC++17/20 的分配器适配器

html - 为什么我的背景视频在移动 View 中不起作用?

PHP静态函数在动态环境中调用

ruby-on-rails - 在 Rails 启动期间创建类的实例

c++ - qt c++ 无法在 win xp sp1 上运行

c++ - 从位字段中存储和检索带符号的值