protected member and templates

K

karolszk

Hi!

The following program gcc returns error:

class Z
{
int a;
int b;
};

template <class Element>
class A
{
public:
A()
{
}
protected:
//Z *a;
Z& a;
};

template <class Element>
class B : public A<Element>
{
public:
B()
{
};
~B()
{
delete &A<Element>::a; // here is problematic line
}
};

int main()
{
B<int> b;
return 0;
}

protected.cpp: In destructor 'B<Element>::~B() [with Element = int]':
protected.cpp:34: instantiated from here
protected.cpp:16: error: 'Z& A<int>::a' is protected
protected.cpp:28: error: within this context
protected.cpp:28: confused by earlier errors, bailing out

which I can't understand why?? When I change A::a member from reference
to pointer the error not appears.
Why I can't delete protected member A::a from the subclass B....

Please help me,
Karol
 
B

braveconf

This is called two-step compile.implemented after gcc 3.4.
When a member in base class(a template),it has nothing to do with paras
of template,just like "a" in your program,can not be visited in the
derived class.
for detail look up in gcc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top