LNK2019在这种情况下如何解决?一切似乎都是正确的

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++很新,似乎我做的一切都正确,但我仍然收到错误.

gsa*_*ras 2

矩形.cpp 应该是这样的:

#include "Rectangle.h"

int Rectangle::getArea() {
  return this->width*this->height;
}
Run Code Online (Sandbox Code Playgroud)

您不应该在源文件中重新定义类定义,因为您已经在头文件中拥有它了!