cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : C2664: typecast problem from iterator to...
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  C2664: typecast problem from iterator to class type

DmitryG (3)
I have some iterator and some CForm class.

vector<CForm>::const_iterator* m_pvForms;

Then it is initizalized etc.

After:

1
2
3
4
5
6
7
8
vector<CForm>::const_iterator itB = m_pvForms->begin();
vector<CForm>::const_iterator itE = m_pvForms->end();
vector<CForm>::const_iterator it;

for (it = itB; it != itE; ++it)
{
    string test = GetTableName(it);
}


Method GetTableName accepts const CForm* parameter.

In Visual Studio 6.0 everything in fine but in VS.NET 2003 compiling fails with error:

error C2664: 'CDialogSelectForm::GetTableName' : cannot convert parameter 1 from 'std::vector<_Ty>::const_iterator' to 'const CForm *'
with
[
_Ty=CForm
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


I think there is some more strict typecast policy in VS.NET rather than VS6...
Help please, i'm totally stuck.

Sorry for my English and thanks.
|
Duoas (1458)
It is because iterators are classes themselves, not just pointers. You need to first dereference the iterator, and then get the address of the CForm object:

string test = GetTableName( &(*it) );

I think that should do it for you.
|
DmitryG (3)
That hepled, many thanks.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us