E A
E A

Reputation: 13

c++ Inheritance with templates and visibility

I don't understand att all inheritance with templates..

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

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


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

    return 0;
}

Why do I have this error?

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

And all works when I put "Mere()" in public? I can't have "protected" functions for my class "Mere"? Why?

Upvotes: 1

Views: 67

Answers (1)

NPE
NPE

Reputation: 500853

Yes, you can call the base class constructor, even if it is protected. Here is the correct syntax:

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

For a detailed discussion, see Why is protected constructor raising an error this this code?

Upvotes: 3

Related Questions