I am upgrading a VC++ 6.0 project to Visual Studio 2008. It uses STL extensively. It compiles fine on Visual Studio 6, but produces the following error in VS2008: error C2440: 'initializing' : cannot convert from 'const int' to 'MyStruct *' The error is trapped in the STL functional header file. From what I can tell, I've coded it correctly. It doesn't matter how I wrap it in type casting, it still can't recognize that *item is a MyStruct* and not a const int.

I get this error in Visual Studio 2002, 2003, and 2005 as well. Also, it doesn't matter if I use an iterator or a const_iterator, or if I make the struct a class instead.

Here is the source code for the problem block.

// these are already allocated; here just for type reference 
double dValue[]; 
vector<MyStruct*> m_xMyStructItems;
int c = 0;

// ... (snip)
// Here's where the linker problem is:
	for(vector<MyStruct*>::iterator item = m_xMyStructItems.begin(); item != m_xMyStructItems.end(); ++item, ++c) 
	{

		// Format output string according to data type:
		switch ((*item)->m_vtValue.vt) {
			case VT_UI1:
				dValue[c] = (double)(*item)->m_vtValue.bVal;
				break;
//(... snipped rest of switch cases )
		}
	}

I cannot see why this is not working.

If it helps to know, one of the members of MyStruct is a VARIANT, another is a _FILETIME, and it contains three std::string members.

Can someone please help me?

I created a new project in VC++ 6.0, copied the code you posted and compiled. Then imported the *.dsw file into VC++ 2008 Express. It compiled there with no changes, warnings, or errors. So your problem must be someplace else. Here is my program

#include <vector>
#include <string>
#include <windows.h>
using namespace std;

struct MyStruct
{
	VARIANT m_vtValue;
	_FILETIME tm;
	std::string str1, str2, str3;

};


int main()
{
	double dValue[25] = {0}; 
	vector<MyStruct*> m_xMyStructItems;
	int c = 0;

	for(vector<MyStruct*>::iterator item = m_xMyStructItems.begin(); item != m_xMyStructItems.end(); ++item, ++c) 
	{

		// Format output string according to data type:
		switch ((*item)->m_vtValue.vt) {
			case VT_UI1:
				dValue[c] = (double)(*item)->m_vtValue.bVal;
				break;
//(... snipped rest of switch cases )
		}
	}

	return 0;
}

Thanks, that narrows it down a little.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.