| View previous topic :: View next topic |
| Author |
Message |
Dmytro Guest
|
Posted: Sun Jun 18, 2006 9:10 am Post subject: typedef & template |
|
|
Hi!
This code is ok:
template<class T>
struct Container
{
T x;
typedef int size_type;
size_type size() { return sizeof T; }
};
Why the compiler (VC7) does not compile the following code?
template<class T>
struct Container
{
T x;
typedef int size_type;
size_type size() const;
};
template<class T>
Container<T>::size_type Container<T>::size() { return sizeof T; }
---
Thanks
Dmytro |
|
| Back to top |
|
 |
Jakob Bieling Guest
|
Posted: Sun Jun 18, 2006 9:10 am Post subject: Re: typedef & template |
|
|
Dmytro <dmytro.bukhantsov (AT) gmail (DOT) com> wrote:
| Quote: | Why the compiler (VC7) does not compile the following code?
template<class T
struct Container
{
T x;
typedef int size_type;
size_type size() const;
};
template<class T
Container<T>::size_type Container<T>::size() { return sizeof T; }
|
Where (which line in the above snippet) and which error do you get?
My guess is you're missing a 'typename' in the last line.
hth
--
jb
(reply address in rot13, unscramble first) |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Sun Jun 18, 2006 9:10 am Post subject: Re: typedef & template |
|
|
Dmytro wrote:
| Quote: | Hi!
This code is ok:
template<class T
struct Container
{
T x;
typedef int size_type;
size_type size() { return sizeof T; }
};
Why the compiler (VC7) does not compile the following code?
template<class T
struct Container
{
T x;
typedef int size_type;
|
Why use int for a size_type? Does a negative size make sense?
| Quote: | size_type size() const;
};
template<class T
Container<T>::size_type Container<T>::size() { return sizeof T; }
You left out two important things: |
typename Container<T>::size_type Container<T>::size() const {
return sizeof T; }
The typename is required to tell the compiler that
Container<T>::size_type is a type and the const because the prototype
function is const.
--
Ian Collins. |
|
| Back to top |
|
 |
|