Inline classes and template templates... confused

Discussion in 'C++' started by Mark, Sep 17, 2004.

  1. Mark

    Mark Guest

    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;

    }
     
    Mark, Sep 17, 2004
    #1
    1. Advertising

  2. Mark wrote:
    > [...]
    >
    > 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
     
    Victor Bazarov, Sep 17, 2004
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Victor Bazarov <> wrote in message news:<8SE2d.2096$09.us.to.verio.net>...

    > '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
     
    Mark, Sep 18, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    3
    Views:
    526
  2. Sean
    Replies:
    4
    Views:
    693
    Rolf Magnus
    Apr 30, 2006
  3. Replies:
    6
    Views:
    355
    Ron Natalie
    Jul 18, 2006
  4. recover
    Replies:
    2
    Views:
    862
    recover
    Jul 25, 2006
  5. Rahul
    Replies:
    3
    Views:
    480
    James Kanze
    Feb 28, 2008
Loading...

Share This Page