Je suis novice en C++ et je travaille sur un projet où j'ai un tableau d'instances d'une classe, et au sein de cette classe j'ai une structure dans laquelle j'ai une fonction. Comment utiliser cette fonction dans mon bloc de code principal. J'ai essayéTableaux et classes?
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;
}
Vous devriez commencer par poster un code valide. Cela le rendra plus facile à comprendre. – juanchopanza