Topic: Template Class Member Fcn Decl Problems!


Author: smit2204@mary.cs.fredonia.edu (Jacob Matthew Smith)
Date: Sun, 9 Oct 1994 01:26:51 GMT
Raw View
Hello,

  I hope this hasn't been asked recently, I've been in heavy development, and
am trying to get moving again on C++ for use in some very soon future projects.
Anyway, I was working on a class for praoctice today and came into a big
problem.
  The problem seems to be this: I have a member function of a generic class
(template---class) that wants to return something of a type that is defined
within the template class.  I am working with (gnu) g++ right now (which may
be part of the cause?).
  I broke it down into the following piece of code:

/*************************************************************/
template<class GC> class Bob {
  public:
    enum MyType { type_a, type_b };  // NOTE THIS TYPE

    void fcn (void);
    MyType fcn2 (void);
};

// THE FOLLOWING FUNCTION WORKS FINE
template<class GC> void Bob<GC>::fcn (void) { /* the body */ }

// THE FOLLOWING FUNCTIOIN HAS PROBLEMS (NOTE MyType DECLARED IN Bob)
template<class GC> Bob<GC>::MyType Bob<GC>::fcn2 (void) { /* what a bod */ }

// ALSO TRIED THE FOLLOWING (with no luck):
//template<class GC> MyType Bob<GC>::fcn2 (void) { /* what a bod */ }
//template<class GC> Bob<GC>::MyType fcn2 (void) { /* what a bod */ }
/*************************************************************/

Any help/suggestions would be appreciated!!
       --Jaek




Author: jason@cygnus.com (Jason Merrill)
Date: Sun, 9 Oct 1994 07:09:15 GMT
Raw View
>>>>> Jacob Matthew Smith <smit2204@mary.cs.fredonia.edu> writes:

>   The problem seems to be this: I have a member function of a generic class
> (template---class) that wants to return something of a type that is defined
> within the template class.  I am working with (gnu) g++ right now (which may
> be part of the cause?).

It is.  g++ doesn't handle types nested within templates properly.

> Any help/suggestions would be appreciated!!

Until this is fixed you'll need to define such functions within the
template body.

Followups to gnu.g++.help.

Jason