constructor / destructor in template class
-
template class CProtectedVariable { CProtectedVariable() { } ; ~CProtectedVariable() { } protected : T m_Var ; } ;
when i do this and include this another class as a member. I am getting a few compiler errors#include "Protected.h" class OutSideClass { protected : CProtectedVariable m_initState ; };
error C2248: 'CProtectedVariable::CProtectedVariable' : cannot access private member declared in class 'CProtectedVariable' 1> with 1> [ 1> T=bool 1> ]
What am I missing here ?Engineering is the effort !
-
template class CProtectedVariable { CProtectedVariable() { } ; ~CProtectedVariable() { } protected : T m_Var ; } ;
when i do this and include this another class as a member. I am getting a few compiler errors#include "Protected.h" class OutSideClass { protected : CProtectedVariable m_initState ; };
error C2248: 'CProtectedVariable::CProtectedVariable' : cannot access private member declared in class 'CProtectedVariable' 1> with 1> [ 1> T=bool 1> ]
What am I missing here ?Engineering is the effort !
OutSideClass
cannot instantiate itsm_initState
member becauseCProtectedVariable
constructor isprivate
(private
is the default access specifier for a class). You may changetemplate <class T>
class CProtectedVariable
{
CProtectedVariable()
..
};into
template <class T>
class CProtectedVariable
{
public:
CProtectedVariable()
..
};:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
template class CProtectedVariable { CProtectedVariable() { } ; ~CProtectedVariable() { } protected : T m_Var ; } ;
when i do this and include this another class as a member. I am getting a few compiler errors#include "Protected.h" class OutSideClass { protected : CProtectedVariable m_initState ; };
error C2248: 'CProtectedVariable::CProtectedVariable' : cannot access private member declared in class 'CProtectedVariable' 1> with 1> [ 1> T=bool 1> ]
What am I missing here ?Engineering is the effort !
act_x wrote:
What am I missing here ?
Code inside of <> brackets. Remove the < bracket and click the < button above the smileys instead. You might also consider using <pre> instead of <code>, too.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
OutSideClass
cannot instantiate itsm_initState
member becauseCProtectedVariable
constructor isprivate
(private
is the default access specifier for a class). You may changetemplate <class T>
class CProtectedVariable
{
CProtectedVariable()
..
};into
template <class T>
class CProtectedVariable
{
public:
CProtectedVariable()
..
};:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke