Topic: Template syntax question


Author: nimel@my-dejanews.com
Date: 1999/03/04
Raw View
The following code gives strange compiler errors on my compiler, and I didn't
find any reference to related to this problem in the standard (ch. 14). I am
hoping someone could enlighten me about the correct syntax.

If I instead define the function within the template class declaration
my compiler is happy, and another workaround is to add a typedef of
typename T::Type inside the template class, and use that instead.

Example:
template <class T>
class X
{
public:
  X(T::Type arg);
};

// The following definition results in:
// error: 'X<T>::X<T>::X<T>' : unable to resolve function overload
template <class T>
X<T>::X(T::Type arg)
{
}

class A
{
public:
  typedef int Type;
};

int main()
{
  X<A> foo(7);
  return 0;
}

/Niklas Mellin


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/05
Raw View
nimel@my-dejanews.com wrote:
...
> template <class T>
> class X
> {
> public:
>   X(T::Type arg);
> };

You need a 'typename' keyword before T::Type. Without it, the compiler
must assume that T::Type is a member of T, rather than a type.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]