0
正如標題所說,我無法從我的主文件訪問基類的公共成員變量。無法訪問的基類公共成員變量
Entity.h:14:10: error: 'char Entity::character' is inaccessible
entity.h:
#include "Vector2.h"
#include <Windows.h>
class Entity {
public:
Entity(char character, WORD color, Vector2<int> pos);
Vector2<int> pos;
Vector2<int> vel;
char character;
WORD color;
};
player.h:
#include "Entity.h"
class Player : Entity {
public:
Player(int lives, char character, WORD color, Vector2<int> pos);
int lives;
int points;
};
構造函數調用主:
int main(){
Player player(0, 'C', FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, playerSpawn);
char c = player.character; // error here
return 0;
}
有什麼建議?
請注意,單詞[屬性](http://en.cppreference.com/w/cpp/language/attributes)可能不應該用於描述成員變量。 – Default
我移動了你的代碼,希望能夠讓它看起來更清晰一些。如果您覺得我違反或摧毀了某些東西,請隨時[編輯](https://stackoverflow.com/posts/44301405/edit)! – Default