我有這樣的furniture.h:類問題在C++
#include <iostream>
#include <string>
using namespace std;
class Furniture {
public:
Furniture();
virtual ~Furniture();
void setname(string name);
void setprice(double price);
int getprice();
string getname();
private:
string name;
int price;
protected:
static int NumberOfItems;
int Id;
}
而這furniture.cpp
#include "furniture.h"
void Furniture::setname(string name) {
this->name = name;
}
string Furniture::getname()
{
return this->name;
}
void Furniture::setprice(double price) {
this->price = price;
}
int Furniture::getprice() {
return this->price;
}
int main() {
Furniture *model = new Furniture();
model->setname("FinalDestiny");
model->setprice(149.99);
cout<<"Model name: "<<model->getname()<<" - price = "<<model->getprice();
}
,但我得到了一些錯誤,如:
錯誤1個錯誤C2628 :'Furniture'後跟'void'是非法的(你忘了';'?)c:\ final \ facultate \ poo \ laborator 1 \ furniture.cpp 3 1 POO_lab
Error 2錯誤C2556:'Furniture Furniture :: setname(std :: string)':重載函數只與'void Furniture :: setname(std :: string)'的返回類型不同'c:\ final \ facultate \ poo \ laborator 1 \ furniture.cpp 3 1 POO_lab
錯誤3錯誤C2371:'Furniture :: setname':redefinition;不同的基本類型c:\ final \ facultate \ poo \ laborator 1 \ furniture.cpp 3 1 POO_lab
錯誤5錯誤C2264:'Furniture :: setname':函數定義或聲明中的錯誤;函數不叫c:\ final \ facultate \ poo \ laborator 1 \ furniture.cpp 19 1 POO_lab
我在做什麼錯?
錯誤1錯誤C2628: '傢俱',然後 '無效' 是非法的**(你忘了一個 ';'?)** – 2012-03-18 22:10:02
RTFE:閱讀...錯誤。 – adelphus 2012-03-18 22:26:48