
Container of class defined within another class
Hello.
I'm porting some C++ code from Solaris to NT, using MSVC++ 5.0 w/o SP3.
It seems that MS's implementation of STL does not support container of a
class defined within another class. For example,
#include <vector>
using namespace std;
class X
{
public:
class Y
{
int i;
public:
Y(): i(0) {}
};
vector<Y> vy;
Quote:
};
which results in the following compilation error:
--------------------Configuration: Study - Win32
Debug--------------------
Compiling...
Study.cpp
C:\Program Files\DevStudio\VC\INCLUDE\vector(103) : error C2065: 'Y' :
undeclared identifier
C:\Program Files\DevStudio\VC\INCLUDE\vector(103) : error C2440:
'default argument' : cannot convert from 'int' to 'const class X::Y &'
Reason: cannot convert from 'int' to 'const class X::Y'
No constructor could take the source type, or constructor overload
resolution was ambiguous
Error executing cl.exe.
Study.obj - 2 error(s), 0 warning(s)
But the same code works fine with HP/SGI's STL.
Does SP3 fix the problem? Or can anyone supply a solution? Thanks a lot.
-Jack
FYI, the source code of <vector> where the error happens is as follows:
template<class _Ty, class _A = allocator<_Ty> >
class vector {
public:
...
void resize(size_type _N, const _Ty& _X = _Ty())
^^^^^
{if (size() < _N)
insert(end(), _N - size(), _X);
else if (_N < size())
erase(begin() + _N, end()); }
My guess is the default argument _X = _Ty() is the problem.