我是新來的C + +和一個項目,我有一個類的實例數組,並在該類中,我有一個結構,我有一個函數。 如何在我的主代碼塊中使用該功能。我試過數組和類?
class artwork {
struct art {
// the struct art contains important information such as artist, title and medium.
private:
string artist;
public:
void setArtist(string values);
string getArtist();
};
void artwork::art::setArtist(string values) {
artist = values;
}
int main(){
artwork myartwork[500];
for (int i = 0; i < 500; i++) {
///-----------------------------------
///-----------------------------------
// below is where the error occurs? How do I reference setArtist?
///-----------------------------------
///-----------------------------------
cout << myartwork[0].art.setArtist("Tim");
}
system("pause");
return 0;
}
您應該先發布有效的代碼。這會讓你更容易理解。 – juanchopanza