Inline classes and template templates... confused

M

Mark

I have a pretty strange problem on my hands. I know of the syntax for
what I'm trying to do without templates, but not with, and I've come
to a point now where I don't really know where else to look for
answers, so I figured I'd post here!

As you can see below, I have OneNorm as an inline class of Set, and
OneNorm declared as a friend of Set. However, when I try to access
the private members of Set, I get a compiler error. Does anyone idea
what I've done wrong here?

Thanks,
Mark

PS – CylindricalCoor is an inheriting class of Element.

-----------------compiler error------------------------

set.hpp:13: type `Set<float,CylindricalCoor>' is not a base type for
type `Set<float,CylindricalCoor>::OneNorm'
set.hpp:13: confused by earlier errors, bailing out
make: *** [all] Error 1

-----------------set.h---------------------------------

template<typename T, template <typename> class Element>
class Set {

public:

Set(){}

~Set(){}

...

class OneNorm {

public:

friend class Set;

double operator()();



};

friend class OneNorm;

OneNorm CalcOneNorm;

....

private:

std::vector<Element<T> > SetMembers;

};



-----------------set.hpp---------------------------------



template<typename T, template <typename> class Element>

double Set<T, Element>::OneNorm::eek:perator()()

{

double TotalMags = 0 ;



for(int i = 0; i < Set::SetMembers.size(); i++) //ERROR: line 13

TotalMags = TotalMags + Set::~SetMembers;

return TotalMags;

}
 
V

Victor Bazarov

Mark said:
[...]

As you can see below, I have OneNorm as an inline class of Set, and
OneNorm declared as a friend of Set. However, when I try to access
the private members of Set, I get a compiler error. Does anyone idea
what I've done wrong here?

Thanks,
Mark

PS – CylindricalCoor is an inheriting class of Element.

-----------------compiler error------------------------

set.hpp:13: type `Set<float,CylindricalCoor>' is not a base type for
type `Set<float,CylindricalCoor>::OneNorm'
set.hpp:13: confused by earlier errors, bailing out
make: *** [all] Error 1

-----------------set.h---------------------------------

template<typename T, template <typename> class Element>
class Set {

public:

Set(){}

~Set(){}

...

class OneNorm {

public:

friend class Set;

double operator()();



};

friend class OneNorm;

OneNorm CalcOneNorm;

...

private:

std::vector<Element<T> > SetMembers;

};



-----------------set.hpp---------------------------------



template<typename T, template <typename> class Element>

double Set<T, Element>::OneNorm::eek:perator()()

{

double TotalMags = 0 ;



for(int i = 0; i < Set::SetMembers.size(); i++) //ERROR: line 13

'SetMembers' is not a static member of 'Set'. You simply cannot
get to 'SetMembers' without an instance of 'Set'.
TotalMags = TotalMags + Set::~SetMembers;

return TotalMags;

}


Victor
 
M

Mark

Victor Bazarov said:
'SetMembers' is not a static member of 'Set'. You simply cannot
get to 'SetMembers' without an instance of 'Set'.
Victor

Thanks Victor,

Sorry for the newbie-type question. I saw a very misleading example
in one of my class texts, with some very similar variable names, that
lead me to believe that this type of access was possible with nested
classes in C++. Your comment hit me like a train when I read it; it
doesn't make any sense to access members without an object,
super-class or not --that is, of course, unless they're static.

--ms
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top