Jun 23, 2015 at 11:44am UTC
I have been getting this error
error C2440: 'const_cast' : cannot convert from 'const DataAccess::Common::CTMCTable<taBoundingBox> *' to 'DataAccess::Generic::TTC::CRoadNetwork::CTMCTablesInAreaIterator'
on compilation in Visual C++
The code is
CRoadNetwork::CTMCTablesInAreaIterator::CTMCTablesInAreaIterator(const CRoadNetwork::CTMCTablesInAreaIterator& aOther)
: CRoadNetwork::CTMCTablesInAreaIterator::TSuper(aOther)
, iTMCLocationTable(aOther.iTMCLocationTable)
, iTableData(aOther.iTableData)
{
// Reset using copied iterator
TTMCTablesEntireIterator::Reset(iTableData.begin(), iTableData.end());
// const_cast<int*>(static_cast<const int*>(obj));
//TSuper::Reset(const_cast<CRoadNetwork::CTMCTablesInAreaIterator>(this->operator const CRoadNetwork::CTMCTablesInAreaIterator()), this->End());
<B>
TSuper::Reset(const_cast<CRoadNetwork::CTMCTablesInAreaIterator>(static_cast<CRoadNetwork::CTMCTablesInAreaIterator&>((*this)), this->End()));
</B>
}
Any suggesstions ?
Last edited on Jun 23, 2015 at 11:45am UTC
Jun 23, 2015 at 11:53am UTC
What is this TSuper::Reset(const_cast <CRoadNetwork::CTMCTablesInAreaIterator>
(missing &) good for? There is no const to cast away?
Jun 24, 2015 at 4:48am UTC
The code is the place where the error is generated
TSuper::Reset(const_cast<const CRoadNetwork::CTMCTablesInAreaIterator&>(static_cast<CRoadNetwork::CTMCTablesInAreaIterator&>((*this)), this->End()));
Adding the const doesnt help either
Jun 24, 2015 at 7:48am UTC
Do you even know what const_cast<...>(...) does?
However, the source of compiler error is a missplaced parenthesis:
TSuper::Reset(const_cast<const CRoadNetwork::CTMCTablesInAreaIterator&>(static_cast<CRoadNetwork::CTMCTablesInAreaIterator&> missplaced -> ( <- missplaced (*this)), this->End()));
remove that parenthesis and the compiler should take it.