ohi*_*ano 5 c++ oop linker-errors
我有常见的LNK2019错误,无法弄清楚出了什么问题.
这是我的解决方案浏览器:
这是我的Rectangle.cpp:
class Rectangle
{
public:
int getArea()
{
return this->width*this->height;
}
int width;
int height;
};
Run Code Online (Sandbox Code Playgroud)
这是我的Rectangle.h:
#pragma once
class Rectangle
{
public:
int getArea();
int width;
int height;
};
Run Code Online (Sandbox Code Playgroud)
这是我的Functions.cpp:
#include <iostream>
#include "Rectangle.h";
using namespace std;
int main()
{
Rectangle r3{ 2, 3 };
cout << r3.getArea();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我对C++很新,似乎我做的一切都正确,但我仍然收到错误.
矩形.cpp 应该是这样的:
#include "Rectangle.h"
int Rectangle::getArea() {
return this->width*this->height;
}
Run Code Online (Sandbox Code Playgroud)
您不应该在源文件中重新定义类定义,因为您已经在头文件中拥有它了!