Monday, 15 August 2011

c++ - How can I call a template's private constructor from a different template instantiation -



c++ - How can I call a template's private constructor from a different template instantiation -

for example:

template<class t> class myclass { public: template<class u> myclass<u> dosomething() { homecoming myclass<u>(); } //can't access private constructor private: myclass() {} }

template-voodoo answers , acceptable. what's of import me class can create , homecoming instances of different template parameters, external code cannot phone call particular constructor using.

add next in myclass

template<typename q> friend class myclass;

myclass<int> , myclass<float> resolve exclusively different classes. know nil of eachother, , can't access eachother's privates more 2 totally seperate classes. so, solution have every instantiation of myclass friend every other instantiation can see eachother's privates if same class.

c++ templates c++11

No comments:

Post a Comment