Strange bug: struct is not a type in C++?
Strange bug: struct is not a type in C++?
- Subject: Strange bug: struct is not a type in C++?
- From: Jean-Denis Muys <email@hidden>
- Date: Wed, 08 Oct 2008 09:24:52 +0200
Hi,
As a relative newcomer, I have a strange bug in my program, which I
managed to reduce to the tiny C++ code below (use a standard C++ tool
as a project type in XCode).
The compiler reject the "class1<Type>::insideStruct *p2;" declaration
with the following error message:
/.../main.cpp:23: error: expected ';' before '*' token
while prepending "struct" in front of the declaration makes it quite
happy.
Since in C++, structs are types, this shouldn't be: either they are
both correct or they are both incorrect.
Did I miss something? Is this an XCode bug (I use version 3.1.1)? or
my bug?
Thanks for the help,
Jean-Denis.
#include <iostream>
template<class Type>
class class1
{
public:
struct insideStruct
{
int anyInt;
Type fData;
};
insideStruct class1Data;
};
template<class Type>
class class2
{
public:
int class2int;
struct class1<Type>::insideStruct *p1; // Compiler doesn't like this
class1<Type>::insideStruct *p2; // but is just fine with this
};
int main (int argc, char * const argv[]) {
// insert code here...
std::cout << "Hello, Lucky World!\n";
class1<double> c1;
class2<double> c2;
std::cout << "class1 size: " << sizeof(c1) << "\n";
std::cout << "class2 size: " << sizeof(c2) << "\n";
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden