構造体#1(e [0])のコードを取得する必要がありますが、次のエラーが発生します。 ""エラー: 'emp1'のメンバ 'get_code'を要求します。これはポインタ型 'Employee *'(おそらく ' - >'を使用することを意味していますか?) " これを修正する方法を理解できません。プラス、それは私が構造を使用することに拘束されているので、私は " - >"が何であるかはわかりませんが、それが何らかのオペレータか何かであれば、私たちは教えられていないので、それはまだ。 (同様の質問への回答は、使用することをお勧め - 。>私のためにそれdoesntの仕事ので)私も使ってみました *(EMP1).get_code()構造体の配列内の構造体へのポインタ
#include <iostream>
#include <string.h>
using namespace std;
struct Employee{
private:
string code;
string name;
float salary;
public:
void set_code(string c){
code=c;
}
void set_name(string n){
name=n;
}
void set_sal(float s){
salary=s;
}
string get_code(){
return code;
}
string get_name(){
return name;
}
float get_sal(){
return salary;
}
};
int main(void) {
Employee e[2],*emp1,*emp2;
string c,n;
float s;
for (int i=0;i<2;i++){
cout<<"Enter code for employee "<<i+1;
cin>>c;
e[i].set_code(c);
cout<<"Enter name for employee "<<i+1;
cin>>n;
e[i].set_name(n);
cout<<"Enter salary for employee "<<i+1;
cin>>s;
e[i].set_sal(s);
}
*emp1=e[0];
cout<<emp1.get_code();
}
エラーメッセージについては何が不明ですか? –
エラーは 'emp1-> get_code()'を使用するように指示しています。 'x-> y()'は一般的に '(* x).y()'と同じです。 –
_ "私も' *(emp1).get_code() '"を使用してみました。 " –