c++ template inheritance scheme

PinkFloyd

I wonder if the way I code this is correct. Can I create a template claas that inherits from a template class ? If I can, is the following code correct :

template<typename Type>
class A{
    public:
        A(){};
        method_A(){//do whatever}
    protected:
        int a;
}

the second class is :

template<typename Type>
class B:public<Type> A {
    public:
        B(){};
        method_B(){this->a=0; this->method_A();}
    protected:
        int b;
}

and my last class is :

class C:public<double> B{
    public:
        C(){};
        method_C(){ b = 0; method_B();}
    protected:
        int c;
}

Why are the this-> mandatory in the class B but not in the class C ? And in general, should I always add this-> to reference arguments or methods that belong to the same class ?

Vaughn Cato

This is specifically addressed in section 14.6.2p3 of the C++03 and C++11 standards:

In the definition of a class template or a member of a class template, if a base class of the class template depends on a template parameter, the base class scope is not examined during unqualified name lookup either at the point of definition of the class template or member or during an instantiation of the class template or member.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++ Template Inheritance

From Dev

Racket/Scheme C++ Extensions and Inheritance

From Dev

Inheritance and template function c++

From Dev

C++ template specialisation & inheritance

From Dev

C++ template class inheritance

From Dev

c++ template abstract inheritance

From Dev

Template class in c++ inheritance in template

From Dev

C++ Inheritance: Calling subclass function of template

From Dev

C++: Inheritance from template parameter

From Dev

C++ template partial specialization with inheritance

From Dev

C++11 variadic template + inheritance

From Dev

C++ template subclass and multiple inheritance ambiguity

From Dev

insert an template object in vector with inheritance c++

From Dev

C++11 Cannot cast template inheritance

From Dev

C++ template declaration with inheritance list

From Dev

Template and inheritance

From Dev

Full template instantiation forced in C++ template inheritance?

From Dev

c++ template class inheritance with other template methods

From Dev

C++ Calling function that has template which has inheritance

From Dev

ambiguous error : C++11 use variadic template multiple inheritance

From Dev

C++: Fix class template specialization / inheritance issue

From Dev

ambiguous error : C++11 use variadic template multiple inheritance

From Dev

template member function inheritance

From Dev

Nested polymer template inheritance

From Dev

template inheritance and abstract class

From Dev

Inheritance with possible template failure

From Dev

flask Template Inheritance tutorial

From Dev

Template class arguments inheritance

From Dev

Vuejs template inheritance