J
jdmuys
Hi,
I have a strange bug in my code, which I managed to reduce to the tiny
C++ program below.
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 a compiler bug (I tried two different
compilers including GCC4 on MacOS X)? 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 is just fine with
this
class1<Type>::insideStruct *p2; // but doesn't like this
};
int main (int argc, char * const argv[]) {
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;
}
I have a strange bug in my code, which I managed to reduce to the tiny
C++ program below.
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 a compiler bug (I tried two different
compilers including GCC4 on MacOS X)? 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 is just fine with
this
class1<Type>::insideStruct *p2; // but doesn't like this
};
int main (int argc, char * const argv[]) {
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;
}