C++ Template question

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
struct Base
{
	template <class T=Base>
	struct Type
	{
		template <class Extender>
		struct ExtendHelper
		{
			template <class U=ExtendHelper>
			struct Type : T::Type<U>, Extender
			{
				Type(typename T::Type<T> &rhs) :
				T::Type<U>(rhs)
				{
				}
				Type() {}
			};
		};

		template <class Extender>
		struct Extend : ExtendHelper<Extender>::Type<>
		{
			template <class C>
			Extend(C &rhs) : ExtendHelper<Extender>::Type<>(rhs)
			{
			}
		};      
	};
};


struct Data { };

int main()
{
	Base::Type<Base> base;
	Base::Type<Base>::Extend<Data> baseWithData(base);
	return 0;
}


This fails with :


Error 1 error C2614: 'Base::Type<T>::Extend<Extender>' : illegal member initialization: 'Type<Base::Type<Base::Type<Base>::ExtendHelper<Data> >::ExtendHelper<Data> >' is not a base or member c:\users\stefanos\documents\visual studio 2010\projects\stackoverflow\stackoverflowtestbench\main.cpp 30 1 StackOverflowTestBench


That's not my code but I am having a really hard time understanding wth is going on here. Any help is appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
struct Base
{
	template <class T=Base>
	struct Type
	{
		template <class Extender>
		struct ExtendHelper
		{
			template <class U=ExtendHelper>
			struct Type : T::Type<U>, Extender
			{
				Type(typename T::Type<T> &rhs) // : T::Type<U>(rhs)
				{
				}
				Type() {}
			};
		};

		template <class Extender>
		struct Extend : ExtendHelper<Extender>::Type<>
		{
			template <class C>
			Extend(C &rhs) : Base::Type<T>::ExtendHelper<Extender>::Type<>(rhs)
			{
			}
		};      
	};
};


struct Data { };

int main()
{
	Base::Type<Base> base;
	Base::Type<Base>::Extend<Data> baseWithData(base);
	return 0;
}

Inside the realization of the template class Extend name ExtendHelper is not declared, so you need to use its full form - it's first.
The second is that inside the constructor of template class Type you call a constructor of its base type T::Type<U>, but if you create an object of the type Base::Type<Base>::Extend<Data>, which is baseWithData of, T is Base and Base::Type< ... >(Base::Type<Base>&) doesn't exist.
Topic archived. No new replies allowed.