Connecting Tech Pros Worldwide Forums | Help | Site Map

explicitly initializing

Bob Smith
Guest
 
Posts: n/a
#1: Jul 19 '05

Given this:

<snip>
typedef std::map<string, QxEvent> QxEventContainerBase;

class QxEventContainer:public QxEventContainerBase{
public:
//!Default constructor
QxEventContainer();
QxEventContainer( const QxEventContainer & ec );
QxEventContainer & operator=( const QxEventContainer& ec );

......
};

QxEventContainer::QxEventContainer( const QxEventContainer & ec ){
*this::
m_interval = ec.m_interval;
}
QxEventContainer & QxEventContainer::operator=( const QxEventContainer&
ec ){
if ( this != &ec ){
m_interval = ec.m_interval;
}
return *this;
}

</snip>


I have a typedef as a base class for a container type class. Now I get a
warning saying that the template *should* be explicitly initialized in
the copy constructor. Now, what does that mean?and how do I fix it.
Thank's for any help.


This is the error I get:

qxeventcontainer.cpp:11: warning: base class `class
map<basic_string<char,string_char_traits<char>,__d efault_alloc_template<true,0>[color=blue]
>,QxEvent,less<basic_string<char,string_char_trait s<char>,__default_alloc_template<true,0> > >,__default_alloc_template<true,0> >' should be explicitly initialized in the copy constructor[/color]


regards
/B


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 19 '05

re: explicitly initializing


"Bob Smith" <bobsmith@jippii.fi> wrote...[color=blue]
>
> Given this:
>
> <snip>
> typedef std::map<string, QxEvent> QxEventContainerBase;
>
> class QxEventContainer:public QxEventContainerBase{
> public:
> //!Default constructor
> QxEventContainer();
> QxEventContainer( const QxEventContainer & ec );
> QxEventContainer & operator=( const QxEventContainer& ec );
>
> .....
> };
>
> QxEventContainer::QxEventContainer( const QxEventContainer & ec ){
> *this::
> m_interval = ec.m_interval;
> }
> QxEventContainer & QxEventContainer::operator=( const QxEventContainer&
> ec ){
> if ( this != &ec ){
> m_interval = ec.m_interval;
> }
> return *this;
> }
>
> </snip>
>
>
> I have a typedef as a base class for a container type class. Now I get a
> warning saying that the template *should* be explicitly initialized in
> the copy constructor. Now, what does that mean?and how do I fix it.
> Thank's for any help.
>
>
> This is the error I get:
>
> qxeventcontainer.cpp:11: warning: base class `class
>[/color]
map<basic_string<char,string_char_traits<char>,__d efault_alloc_template<true
,0>[color=blue]
>
>,QxEvent,less<basic_string<char,string_char_trait s<char>,__default_alloc_te[/color]
mplate<true,0> > >,__default_alloc_template<true,0> >' should be explicitly
initialized in the copy constructor

std::map<>'s default c-tor is declared "explicit". Since you're
inheriting from std::map, you need to construct the base class
explicitly in the copy c-tor, because if the initialisation is
omitted, the default initialisation is used, and for std::map it
is "explicit".

Victor


Closed Thread