這裏用繩子編譯沒有發現部件的錯誤代碼:當我嘗試把班級分成頭,我得到當我在課堂上
Classes.h
#ifndef CLASSES_H
#define CLASSES_H
// Team Class
class Team {
public:
string title, initials;
};
// End
// Player Class
class Player {
public:
int skill, cost;
string name;
};
// End
// Coach Class
class Coach {
int cash, cost, players;
public:
string name;
void set_values (int, int);
int total (void) {return (cash - cost);};
};
// End
#endif
類。 CPP
#include "Classes.h"
// Set Total Cash for Coach
void Coach::set_values (int a, int b) {
cash = a;
cost = b;
}
// End
Main.cpp的
#include <iostream>
#include <string>
#include "classes.h"
當我編譯它沒有找到縮寫成員或名稱成員,即字符串。爲什麼以及如何解決這個問題。
即
main.cpp:22: error: ‘class Player’ has no member named ‘name’
main.cpp:28: error: ‘class Coach’ has no member named ‘name’
main.cpp:29: error: ‘class Coach’ has no member named ‘name’
main.cpp:30: error: ‘class Player’ has no member named ‘name’
main.cpp:35: error: ‘class Team’ has no member named ‘title’
main.cpp:36: error: ‘class Team’ has no member named ‘title’
main.cpp:38: error: ‘class Team’ has no member named ‘initials’
main.cpp:39: error: ‘class Team’ has no member named ‘initials’
main.cpp:40: error: ‘class Player’ has no member named ‘name’
main.cpp:40: error: ‘class Team’ has no member named ‘title’
main.cpp:41: error: ‘class Team’ has no member named ‘initials’
main.cpp:41: error: ‘class Player’ has no member named ‘name’
main.cpp:41: error: ‘class Coach’ has no member named ‘name’
或者 在文件中包含從main.cpp中:9:
classes.h:7: error: ‘string’ does not name a type
classes.h:15: error: ‘string’ does not name a type
classes.h:23: error: ‘string’ does not name a type
請幫幫忙!我是新手,所以它可能是我無法做的或者簡單的修復。
感謝您的幫助。 – user1119577 2011-12-28 15:45:45
這是否解決了它? – hmjd 2012-01-03 21:42:36