0

I am trying to use a class local type definition in a constructor declaration. both the classes are templates, here is the code.

template < typename T>
class complexType
{
    public:
    using value_type = T;
    complexType( T t ) {}
};


template <typename containedType >
class container
{
    public:
    container ( containedType::value_type v ) { return; }
    //container ( int v ) { return; }
};

int main(int ac, char **av)
{
    container <complexType<int>> c(100);
    return 0;
}

if i use the second constructor definition which is being passed an int, the code builds fine. i cannot reason why the code won't build.

Ravikumar Tulugu
  • 1,702
  • 2
  • 18
  • 40
  • Possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – n. m. could be an AI Dec 14 '18 at 07:10

1 Answers1

1

value_type is dependent name, which depends on template argument, in such case you need to use typename to indicate that value_type is type:

template <typename containedType >
class container
{
    public:
    container ( typename containedType::value_type v ) { return; }
                ^^^^^^^ 
    //container ( int v ) { return; }
};
rafix07
  • 20,001
  • 3
  • 20
  • 33