Wednesday, December 18, 2013

typedef of class vs class?

Newsgroup: comp.lang.c++

Subject: typedef of class vs class?

From: Ed Anson <EdAnson@...>

Date: Wed, 18 Dec 2013 19:22:56 -0500



As I read the standard (and various texts on the language) a typedef of

a class is simply a synonym for the class name. So I am surprised that

the following code fails to compile on any C++ compiler I have access to:



class bar;



template <class T>

class foo

{

public:

foo(const T& v) : m(v) {}

T m;

};



typedef foo<int> bar;





Gcc 4.6.3 gives the following error [as slightly mangled by putty]:

TypedefAnomaly.cpp:11:18: error: conflicting declaration âtypedef class

foo<int> barâ

TypedefAnomaly.cpp:1:7: error: âstruct barâ has a previous declaration

as âstruct barâ



Other compilers claim that the forward declaration of bar is

incompatible with the typedef, but don't say why. Is there some fine

point in the C++ standard that I am missing? Must be, since it's

unlikely that all the compilers have the same bug.



/Ed









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?154605-typedef-of-class-vs-class&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment