I start this topic in response to a bug report (see ID=2735592).
wxJSON did not compile on mingw, gcc4; at first glance, it seems the problem related to wxWidgets 2.8.10 but it is not. The library compiles fine on my linux machine and on windows using BCC 5.5.
I thought the problem may be related to wxHashMap and its macros so I decided to implement a new feature in wxJSON: by default, the library uses the wxWidget's own implementation of container classes but the user may specify a flag to force the library using STL containers: sdt::vector and std::map.
I wrote the code and got a pletora of compiler's errors. It seems the problem is related to STL which do not like forward declations.
In order to keep the problem simple, I wrote a code fragment that illustrate the error:
Code: Select all
#include <vector>
class MyClass
{
public:
int iData;
MyClass( int i = 0)
{
iData = i;
}
int GetInt() const
{
return iData;
}
};
typedef std::vector<MyClass> MyClassArray;
Code: Select all
#include <vector>
// forward declaration needed
class MyClass2Array;
class MyClass2
{
public:
int iData;
MyClass2( int i = 0)
{
iData = i;
}
int GetInt() const
{
return iData;
}
MyClass2Array* array; // the array
};
typedef std::vector<MyClass2> MyClass2Array;
Here the compiler output:
Code: Select all
samples/teststd.cpp:74: error: conflicting declaration ‘typedef class std::vector<MyClass2, std::allocator<MyClass2> > MyClass2Array’
samples/teststd.cpp:57: error: ‘struct MyClass2Array’ has a previous declaration as ‘struct MyClass2Array’
samples/teststd.cpp: In function ‘int main(int, char**)’:
samples/teststd.cpp:84: error: aggregate ‘MyClass2Array array2’ has incomplete type and cannot be defined
samples/teststd.cpp:84: warning: unused variable ‘array2’
make: *** [teststd.o] Error 1
Is your compiler able to compile the code snippset (you find it in the attachment)?
Luciano