2016-12-13 4 views
1

、視認性の継承..C++のテンプレートと私はテンプレートと、すべての継承ATT理解していない

template <typename T> 
class Mere 
{ 
protected: 
    Mere(); 
}; 

class Fille2 : public Mere<int> 
{ 
protected: 
    Fille2(){ 
     Mere(); 
    } 
}; 


int main(int argc, char** argv) { 

    return 0; 
} 

は、なぜ私はこのエラーがありますか?

main.cpp:22:5: error: 'Mere<T>::Mere() [with T = int]' is protected 
Mere(); 

私は「公開」を公開するとすべての作品が表示されますか?私は自分のクラス "Mere"の "protected"関数を持つことができないのですか?どうして?

+3

参照...([こちら]を参照のhttp:// melpon。 org/wandbox/permlink/DtiZ3q60YyVytvju)の実行方法について –

答えて

3

はい、protectedであっても、基本クラスのコンストラクタを呼び出すことができます。ここでは正しい構文は次のとおりです。詳細な議論については

class Fille2 : public Mere<int> 
{ 
protected: 
    Fille2(): Mere() { 
    } 
}; 

、あなたがC++で親クラスのコンストラクタを呼び出すか、これがないWhy is protected constructor raising an error this this code?

関連する問題