ユーザーに文字列の入力を求めるプロジェクトに取り組んでおり、get 関数と set 関数を使用して文字列を表示するだけです。ただし、実際にユーザーが文字列を入力してから、それらを get および set 関数に渡すという問題があります。ここに私のコードがあります: これは私の Main.cpp です:
#include "stdafx.h"
#include <iostream>
#include "Laptop.h"
#include<string>
using namespace std;
int main()
{
Laptop Brand;
string i;
cout << "Enter your brand of laptop : ";
cin >> i;
Brand.setbrand (i);
return 0;
}
これは私の Laptop.cpp です:
#include "stdafx.h"
#include <iostream>
#include "Laptop.h"
#include <string>
using namespace std;
void Laptop::setbrand(string brand)
{
itsbrand = brand;
}
string Laptop::getbrand()
{
return itsbrand;
}
これは私の laptop.h です:
#include<string>
class Laptop
{
private :
string itsbrand;
public :
void setbrand(string brand);
string getbrand();
};
私の laptop.cpp では、setbrand と getbrand にエラーがあります。getbrand と setbrand は互換性がないと言われています。パラメータを介して文字列を渡していることと関係があると確信しています。何か案は?