Implicit user-conversion error

T

tim

Our coding standard checker is reporting an implicit user conversion
for the following:

===
std::vector<PepLines>* ptr = NULL;
std::map<peppage::ePepPage, std::vector<PepLines>*>::iterator mapiter =
NULL;

//create the containers to put the PepLines into, one vector for each
pep page
//then pass the pointer into the container. The destruction of these
objects
//will be handled in the CPepPageGraphics destructor.
for(int
looper=peppage::pEP_PAGE_NULL;looper<peppage::pEP_PAGE_END_PAGE;looper++)
{
ptr = new std::vector<PepLines>;
m_PageGraphicsCollection.insert(
make_pair(static_cast<peppage::ePepPage>(looper),ptr ) );
}
===
m_PageGraphicsCollection is defined thus:

std::map<peppage::ePepPage, std::vector<PepLines>*>
m_PageGraphicsCollection;
===

The error is noted on the last line of code,
m_PageGraphicsCollection.insert...

I thought I'd matched up my types correctly, any ideas?
 
I

Ivan Vecerina

: Our coding standard checker is reporting an implicit user conversion
: for the following:
:
: ===
: std::vector<PepLines>* ptr = NULL;
: std::map<peppage::ePepPage, std::vector<PepLines>*>::iterator mapiter =
: NULL;

This is simply illegal: an iterator cannot legally be initialized
with a pointer or a NULL.
You need to either leave it default-initialized (but you then cannot
use the iterator until a value is assigned to it), or you must
set it to someCollection.end() .
Keep in mind that behavior is undefined if you compare iterators
that do not point into the same collection instance.

: //create the containers to put the PepLines into, one vector for each
: pep page
: //then pass the pointer into the container. The destruction of these
: objects
: //will be handled in the CPepPageGraphics destructor.
: for(int
:
looper=peppage::pEP_PAGE_NULL;looper<peppage::pEP_PAGE_END_PAGE;looper++)
: {
: ptr = new std::vector<PepLines>;
: m_PageGraphicsCollection.insert(
: make_pair(static_cast<peppage::ePepPage>(looper),ptr ) );
: }
This incomplete code extract is confusingly incomplete.
How is mPageGraphicsCollection declared ?

: ===
: m_PageGraphicsCollection is defined thus:
:
: std::map<peppage::ePepPage, std::vector<PepLines>*>
: m_PageGraphicsCollection;
: ===
:
: The error is noted on the last line of code,
: m_PageGraphicsCollection.insert...
:
: I thought I'd matched up my types correctly, any ideas?

You really should use typedefs, this will clarify your
code and help avoid errors.


Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top