我很久没有使用C++了,我从来没有真正掌握过类。
我决定通过制作一个小型几何应用来重新学习课程。
这里是square.h:C++构造函数问题
class Square{
public:
float width;
float height;
float area;
float perimeter;
void Square(int,int);
void Square();
void ~Square();
};
这里是square.cpp:
#include "square.h"
Square::Square (int w, int h){
width = w;
height = h;
area = width * height;
perimeter = (width*2)+(height*2);
}
Square::Square(){
}
Square::~Square(){
}
当我运行/筹建方案,它说error: return type specification for constructor invalid
我想这是说的构造函数和析构函数应该是void
以外的东西,但我认为我错了。
为什么当宽度和高度存储为浮点数时,构造函数参数ints是什么? –