I'm not sure why you are adding a template parameter of type Inner , since you define holder as a type based on Container and Inner , both of which are available to indicate that you are declaring a holder.
Do you plan to use any type other than struct inner as a template parameter for Container ? If not, the following simplified code is compiled and launched for me in VS2010:
#include <vector> #include <stdio.h> template <typename C> struct inner{ C * objects[16]; bool hasobj; inner():hasobj(false){} }; template <typename T> class Container { inner<Container> holder; T value; public: Container(const T& valueP){ value = valueP; } void AddChild(Container* rhs){ holder.objects[0] = rhs; //Always using first location, just for example holder.hasobj = true; } void PrintStuff()const{ if(holder.hasobj){ holder.objects[0]->PrintStuff(); } printf("VAL IS %d\n", value); } }; int main(){ Container<int> c(10); Container<int> c1(20); c1.AddChild(&c); c1.PrintStuff(); }
In principle, it is assumed that the Container always determines the holder in terms of Inner , which helps get rid of the additional template parameter in determining the Container . Hope this helps :) Arun
source share