D
Denis Remezov
BCC said:Given this test code:
.h file
--------------
#include <iostream>
#include <string>
class CContainer {
public:
typedef std::string::size_type size_type;
static const size_type npos2 = std::string::npos;
};
class CTest {
public:
void Foo(CContainer::size_type to = CContainer::npos2);
};
.cpp file
---------------
#include "TestApp.h"
using namespace std;
int main()
{
CTest ct;
ct.Foo();
return 0;
}
void CTest::Foo(CContainer::size_type to /* = CContainer::npos2 */)
{
cout << "To == " << to << endl;
cout << "NPOS == " << string::npos << endl;
}
My output is:
To == 0
NPOS == 4294967295
Why is To not equal to NPOS????? This snippet is from a larger chunk of
code that was originally compiled on solaris, and in porting it to windows
To is not initialized as I think it should be. Dont have a sun machine to
test it on though.
Any one have any suggestions on what is going on? Easy to work around, but
the behavior is incorrect as far as I can tell. This was compiled under
.NET 2003 btw.
I've no idea if this would help, and I can't run MSVC to test this idea out,
but I would still provide a definition for npos2 to make the program
perfectly valid:
const CContainer::size_type CContainer::npos2;
Denis