Topic: Is this legal in ANSI C++?
Author: "John Scott" <john-scott@no.spam.please.bigfoot.com>
Date: Sat, 30 Jun 2001 23:05:49 GMT Raw View
According to Scott Meyers' Effective C++ Second Edition, the following is
legal (see Item 34 in the book):
class Date;
Date returnADate(); // Return by value.
This is because they are only declarations. If anybody wants to call
returnADate() then class Date must be defined.
My understanding is that in the same way, the template <class T> ... is only
a declaration. If you actually tried to use it somewhere without first
defining class Foo, you would get a compile time error.
I assume the HP compiler is incorrect, however, I might be mistaken...
Regards
John.
"Jeroen Dirks" <jeroen.dirks@sympatico.ca> wrote in message
news:3b3b38c7.0@newsfeed.jdedwards.com...
> I have some code that does the following:
>
> class Foo;
>
> class FooBase {
> public:
>
> // this returns by value!!!!
> template <class T> Foo makeFoo( T tee ) const
> {
> Foo retVal;
> return retVal;
> };
> };
>
> class Foo : public FooBase {
> public:
> Foo();
> virtual ~Foo();
>
> Foo makeFooInt( const Foo & f )
> {
> return f.makeFoo( 5 );
> }
> };
>
> It compiles on our NT, AIX and SUN box. The HP aCC compiler however seems
> not to allow this. It this valid according to the C++ standard? It seems a
> bit freaky to me...
>
> Jeroen Dirks
>
>
> ---
> [ 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://www.research.att.com/~austern/csc/faq.html ]
>
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: "Jeroen Dirks" <jeroen.dirks@sympatico.ca>
Date: Thu, 28 Jun 2001 21:06:54 GMT Raw View
I have some code that does the following:
class Foo;
class FooBase {
public:
// this returns by value!!!!
template <class T> Foo makeFoo( T tee ) const
{
Foo retVal;
return retVal;
};
};
class Foo : public FooBase {
public:
Foo();
virtual ~Foo();
Foo makeFooInt( const Foo & f )
{
return f.makeFoo( 5 );
}
};
It compiles on our NT, AIX and SUN box. The HP aCC compiler however seems
not to allow this. It this valid according to the C++ standard? It seems a
bit freaky to me...
Jeroen Dirks
---
[ 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://www.research.att.com/~austern/csc/faq.html ]