T
Tomás
First of all, the following will compile for me without any problems:
class BearerOfType
{
public:
class SpecialType {};
};
template<class T>
class Base
{
public:
typedef typename T::SpecialType SpecialType;
int NormalMemberFunction() const;
};
template<class T>
int Base<T>::NormalMemberFunction() const
{
return 5;
}
int main()
{
Base< BearerOfType > k;
}
The compiler compiles it silently with no errors and no warnings.
Now, if I change the return type of the member function from "int" to
"SpecialType", then I get a weird syntax error. First of all here's the code
(copied verbatim with line numbers):
01: class BearerOfType
02: {
03: public:
04:
05: class SpecialType {};
06: };
07:
08:
09: template<class T>
10: class Base
11: {
12: public:
13: typedef typename T::SpecialType SpecialType;
14:
15: SpecialType NormalMemberFunction() const;
16: };
17:
18: template<class T>
19: SpecialType Base<T>::NormalMemberFunction() const
20: {
21: return SpecialType();
22: }
23:
24: int main()
25: {
26: Base< BearerOfType > k;
27: }
And here's what my compiler gave me:
toopie.cpp:19: syntax error before `<' token
toopie.cpp:19: `T' was not declared in this scope
toopie.cpp:19: template argument 1 is invalid
toopie.cpp:20: warning: ISO C++ forbids declaration of
`NormalMemberFunction'
with no type
toopie.cpp:20: non-member function `int NormalMemberFunction()' cannot have
`
const' method qualifier
toopie.cpp: In function `int NormalMemberFunction()':
toopie.cpp:21: `SpecialType' undeclared (first use this function)
toopie.cpp:21: (Each undeclared identifier is reported only once for each
function it appears in.)
I was sitting there scratching my head thinking what could be wrong... until
I changed the function definition from:
template<class T>
SpecialType Base<T>::NormalMemberFunction() const
to:
template<class T>
Base<T>::SpecialType Base<T>::NormalMemberFunction() const
Now it compiles, but it gives a warning:
toopie.cpp:20: warning: `typename Base<T>::SpecialType' is implicitly a
typename
toopie.cpp:20: warning: implicit typename is deprecated, please see the
documentation for details
Anyone know what's going on here? Any advice appreciated.
-Tomás
class BearerOfType
{
public:
class SpecialType {};
};
template<class T>
class Base
{
public:
typedef typename T::SpecialType SpecialType;
int NormalMemberFunction() const;
};
template<class T>
int Base<T>::NormalMemberFunction() const
{
return 5;
}
int main()
{
Base< BearerOfType > k;
}
The compiler compiles it silently with no errors and no warnings.
Now, if I change the return type of the member function from "int" to
"SpecialType", then I get a weird syntax error. First of all here's the code
(copied verbatim with line numbers):
01: class BearerOfType
02: {
03: public:
04:
05: class SpecialType {};
06: };
07:
08:
09: template<class T>
10: class Base
11: {
12: public:
13: typedef typename T::SpecialType SpecialType;
14:
15: SpecialType NormalMemberFunction() const;
16: };
17:
18: template<class T>
19: SpecialType Base<T>::NormalMemberFunction() const
20: {
21: return SpecialType();
22: }
23:
24: int main()
25: {
26: Base< BearerOfType > k;
27: }
And here's what my compiler gave me:
toopie.cpp:19: syntax error before `<' token
toopie.cpp:19: `T' was not declared in this scope
toopie.cpp:19: template argument 1 is invalid
toopie.cpp:20: warning: ISO C++ forbids declaration of
`NormalMemberFunction'
with no type
toopie.cpp:20: non-member function `int NormalMemberFunction()' cannot have
`
const' method qualifier
toopie.cpp: In function `int NormalMemberFunction()':
toopie.cpp:21: `SpecialType' undeclared (first use this function)
toopie.cpp:21: (Each undeclared identifier is reported only once for each
function it appears in.)
I was sitting there scratching my head thinking what could be wrong... until
I changed the function definition from:
template<class T>
SpecialType Base<T>::NormalMemberFunction() const
to:
template<class T>
Base<T>::SpecialType Base<T>::NormalMemberFunction() const
Now it compiles, but it gives a warning:
toopie.cpp:20: warning: `typename Base<T>::SpecialType' is implicitly a
typename
toopie.cpp:20: warning: implicit typename is deprecated, please see the
documentation for details
Anyone know what's going on here? Any advice appreciated.
-Tomás