我有这个共同的LNK2019错误,并不能找出什么是错的。LNK2019如何解决的情况下?一切似乎是正确的
这里是我的解决方案资源管理:
这里是我的Rectangle.cpp
:
class Rectangle
{
public:
int getArea()
{
return this->width*this->height;
}
int width;
int height;
};
这里是我的Rectangle.h
:
#pragma once
class Rectangle
{
public:
int getArea();
int width;
int height;
};
这里是我的Functions.cpp
:
#include <iostream>
#include "Rectangle.h";
using namespace std;
int main()
{
Rectangle r3{ 2, 3 };
cout << r3.getArea();
return 0;
}
我对C++非常陌生,看起来我做的都正确,但仍然出现错误。
你为什么重新定义cpp文件中的'Rectangle'类?看到这个:https://stackoverflow.com/questions/9579930/separating-class-code-into-a-header-and-cpp-file – NathanOliver
他是什么类? – ohidano
@ohidano他指的是班级。看到我的答案! =) – gsamaras