[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

What's wrong with this class

John Doe

10/24/2008 2:09:00 PM

Hi,

I wrote a small class to enumerate available networks on a smartphone :

class CNetwork
{
public:
CNetwork() {};
CNetwork(CString& netName, GUID netguid):
_netname(netName), _netguid(netguid) {}

~CNetwork() {}

CString& getName() { return _netname; }
GUID getGuid() { return _netguid; }

private:
CString _netname;
GUID _netguid;
};


class CNetworkList
{
public:
typedef std::list<CNetwork*>::iterator NetworkListIt;

CNetworkList() {}

~CNetworkList()
{
Clear();
}

CNetworkList::CNetworkList(const CNetworkList& rhs) {
CopyObj(rhs);
}

CNetworkList& CNetworkList::operator=(const CNetworkList& rhs)
{
CopyObj(rhs);
return *this;
}

void CopyObj(const CNetworkList& rhs)
{
_netlist = rhs._netlist;
}



void Clear()
{
for_each( _netlist.begin(), _netlist.end(), DeletePointer ());
}

void Add(CNetwork* network)
{
_netlist.push_back(network);
}

const CNetwork* getNetwork(CString netNameOrGuid)
{
if ((netNameOrGuid.GetAt(0) == '{') &&
netNameOrGuid.GetLength() == 39)
{
CLSID guid;
if
(SUCCEEDED(CLSIDFromString(netNameOrGuid.GetBuffer(),&guid)))
return getNetwork(guid);
}
else
{
NetworkListIt it;
for (it = _netlist.begin(); it != _netlist.end(); ++it)
if (!(*it)->getName().CompareNoCase(netNameOrGuid))
return (*it);
}
return NULL;
}

const CNetwork* getNetwork(CLSID guid)
{
if (!_netlist.empty())
Clear();

NetworkListIt it;
for (it = _netlist.begin(); it != _netlist.end(); ++it)
if ((*it)->getGuid() == guid)
return (*it);

return NULL;
}

private:
std::list<CNetwork*> _netlist;
};

CNetworkList getNetworkList()
{
int i = 0;
HRESULT hResult;
CNetworkList netList;

while( ConnMgrEnumDestinations( i, &connInfo ) == 0 )
{
CNetwork* pNetWork = new
CNetwork(CString(connInfo.szDescription), connInfo.guid);
if (pNetWork)
{
netList.Add(pNetWork);
}

i++;
}
}

When I call this code :
m_NetworkList = getNetworkList();
I got an assert in a Cstring desctructor so I suppose my class is doing
wrong...
When I debug in step by step I don't really understand the calls, it
seems Clear() is called why it shoudn't.






16 Answers

Victor Bazarov

10/24/2008 2:43:00 PM

0

John Doe wrote:
> Hi,
>
> I wrote a small class to enumerate available networks on a smartphone :
>
> class CNetwork

Why do you need the 'C' in front of the name? I can understand 'SP'
(for smartphone), but 'C'?

> {
> public:
> CNetwork() {};
> CNetwork(CString& netName, GUID netguid):
> _netname(netName), _netguid(netguid) {}

If your class owns the member '_netname' (which it probably should, as
you designed it), consider passing the initialiser for it as a reference
to const:

CNetwork(CString const& netName, GUID...

>
> ~CNetwork() {}
>
> CString& getName() { return _netname; }

This is a bad idea. You are exposing the innards of your class to any
change that you can't control or even know about. If your 'Network'
needs to report its name, this member has to be 'const' and should
return a reference to const:

CString const& getName() cosnt { return _netname; }

> GUID getGuid() { return _netguid; }

Same here:

GUID getGuid() const { return _netguid; }

>
> private:
> CString _netname;
> GUID _netguid;
> };
>
>
> class CNetworkList
> {
> public:
> typedef std::list<CNetwork*>::iterator NetworkListIt;

Does this need to be public?

>
> CNetworkList() {}
>
> ~CNetworkList()
> {
> Clear();
> }
>
> CNetworkList::CNetworkList(const CNetworkList& rhs) {
> CopyObj(rhs);
> }

What is that? Why couldn't you just use the normal copy constructor form:

CNetworkList::CNetworkList(const CNetworkList& rhs) :
netlist(rhs.netlist) {}

? And if it matters, this is pretty much unnecessary because the
compiler will provide you with the copy constructor that does exactly that.

>
> CNetworkList& CNetworkList::operator=(const CNetworkList& rhs)
> {
> CopyObj(rhs);
> return *this;
> }

Again, the assignment operator provided by the compiler will work just
fine, most likely. You don't have to provide your own.

>
> void CopyObj(const CNetworkList& rhs)
> {
> _netlist = rhs._netlist;
> }
>
>
>
> void Clear()
> {
> for_each( _netlist.begin(), _netlist.end(), DeletePointer ());
> }
>
> void Add(CNetwork* network)
> {
> _netlist.push_back(network);
> }

Now, you do realise that your list is made the owner of that pointer
here, right?

>
> const CNetwork* getNetwork(CString netNameOrGuid)

The interface of this function is better if (a) it's 'const' and (b) its
argument is not passed by value:

const CNetwork* getNetwork(CStirng const& netNameOrGuid) const

> {
> if ((netNameOrGuid.GetAt(0) == '{') &&
> netNameOrGuid.GetLength() == 39)
> {
> CLSID guid;
> if
> (SUCCEEDED(CLSIDFromString(netNameOrGuid.GetBuffer(),&guid)))
> return getNetwork(guid);
> }
> else
> {
> NetworkListIt it;
> for (it = _netlist.begin(); it != _netlist.end(); ++it)
> if (!(*it)->getName().CompareNoCase(netNameOrGuid))
> return (*it);
> }
> return NULL;
> }
>
> const CNetwork* getNetwork(CLSID guid)

Same comment as above,

const CNetwork* getNetwork(CLSID guid) const

> {
> if (!_netlist.empty())
> Clear();
>
> NetworkListIt it;
> for (it = _netlist.begin(); it != _netlist.end(); ++it)
> if ((*it)->getGuid() == guid)
> return (*it);
>
> return NULL;
> }
>
> private:
> std::list<CNetwork*> _netlist;
> };
>
> CNetworkList getNetworkList()
> {
> int i = 0;
> HRESULT hResult;
> CNetworkList netList;
>
> while( ConnMgrEnumDestinations( i, &connInfo ) == 0 )
> {
> CNetwork* pNetWork = new
> CNetwork(CString(connInfo.szDescription), connInfo.guid);
> if (pNetWork)

'new' never returns NULL. You should, however, surround it with
'try-catch' since 'new' throws 'std::bad_alloc' if something happens.

> {
> netList.Add(pNetWork);
> }
>
> i++;
> }
> }
>
> When I call this code :
> m_NetworkList = getNetworkList();

Where?

> I got an assert in a Cstring desctructor so I suppose my class is doing
> wrong...
> When I debug in step by step I don't really understand the calls, it
> seems Clear() is called why it shoudn't.

Post complete code and provide a test driver that would produce the
network (instead of 'ConnMgrEnumDesitnations' which C++ doesn't have).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

John Doe

10/24/2008 3:18:00 PM

0

Victor Bazarov wrote:
> John Doe wrote:

So here is the update code (without the try for new I will do it later)
but now I get an error :
error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
'const NetworkList' to 'NetworkList &'

so I have added const to Clear()...


//============================================//
// NetworkManager.h
//============================================//
struct DeletePointer {
template<typename T>
void operator()(const T* ptr) const
{
delete ptr;
}
};

class Network
{
public:
Network() {};
Network(CString const& netName, GUID netguid):
_netname(netName), _netguid(netguid) {}

~Network() {}

CString const& getName() { return _netname; }
GUID getGuid() const { return _netguid; }

private:
CString _netname;
GUID _netguid;
};


class NetworkList
{
typedef std::list<Network*>::iterator NetworkListIt;

public:

NetworkList()
{
}

~NetworkList()
{
Clear();
}

void Clear()
{
for_each( _netlist.begin(), _netlist.end(), DeletePointer ());
}

void Add(Network* network)
{
if (network)
_netlist.push_back(network);
}


const Network* getNetwork(CString const& netNameOrGuid) const
{
if ((netNameOrGuid.GetAt(0) == '{') &&
netNameOrGuid.GetLength() == 39)
{
CLSID guid;
if (SUCCEEDED(CLSIDFromString((LPOLESTR)(LPCTSTR)netNameOrGuid,&guid)))
{
return getNetwork(guid);
}
}
else
{
std::list<Network*>::const_iterator it;
//NetworkListIt it;
for (it = _netlist.begin(); it != _netlist.end(); ++it)
if (!(*it)->getName().CompareNoCase(netNameOrGuid))
return (*it);
}
return NULL;
}

const Network* getNetwork(CLSID guid) const
{
if (!_netlist.empty())
Clear();

std::list<Network*>::const_iterator it;
//NetworkListIt it;
for (it = _netlist.begin(); it != _netlist.end(); ++it)
if ((*it)->getGuid() == guid)
return (*it);

return NULL;
}

private:
std::list<Network*> _netlist;
};

//============================================//
// NetworkManager.cpp
//============================================//
NetworkList getNetworkList()
{
NetworkList netList;

// Simulate we retrieve network list from OS
GUID guid;
netList.Add(new Network(_T("Network1"), guid));
netList.Add(new Network(_T("Network2"), guid));

return netList;
}

//============================================//
// Testcase
//============================================//

void OnGettingNetworkList()
{
NetworkList netList = getNetworkList();
}

When the netList is destroyed I get a debug assertion due to CString
object :

void Release() throw()
{
ATLASSERT( nRefs != 0 ); <<<<< !!!!!!!!!

if( _AtlInterlockedDecrement( &nRefs ) <= 0 )
{
pStringMgr->Free( this );
}
}





Obnoxious User

10/24/2008 3:59:00 PM

0

On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:

> Victor Bazarov wrote:
>> John Doe wrote:
>
> So here is the update code (without the try for new I will do it later)
> but now I get an error :
> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
> 'const NetworkList' to 'NetworkList &'
>
> so I have added const to Clear()...
>
>
[snip]
>
> void Clear()
> {
> for_each( _netlist.begin(), _netlist.end(), DeletePointer());
> }
>

How many times is this function called in your test case?
Most probably two times, right?
And what does it do each time?

[snip]
>
> void OnGettingNetworkList()
> {
> NetworkList netList = getNetworkList();
> }

You return a *copy* of the NetworkList you build in the function.
The first copy dies and deallocates via Clear() all the pointers so
the copy contains invalid pointers, which are deallocated yet again,
that's where the CString fails it assertions, becuase it is already
destroyed.

>
> When the netList is destroyed I get a debug assertion due to CString
> object :
>
> void Release() throw()
> {
> ATLASSERT( nRefs != 0 ); <<<<< !!!!!!!!!
>
> if( _AtlInterlockedDecrement( &nRefs ) <= 0 ) {
> pStringMgr->Free( this );
> }
> }

--
OU
Remember 18th of June 2008, Democracy died that afternoon.
http://frapedia.se/wiki/Information_...

John Doe

10/24/2008 4:15:00 PM

0

Obnoxious User wrote:
> On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:
>
>> Victor Bazarov wrote:
>>> John Doe wrote:
>> So here is the update code (without the try for new I will do it later)
>> but now I get an error :
>> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
>> 'const NetworkList' to 'NetworkList &'
>>
>> so I have added const to Clear()...
>>
>>
> [snip]
>> void Clear()
>> {
>> for_each( _netlist.begin(), _netlist.end(), DeletePointer());
>> }
>>
>
> How many times is this function called in your test case?
> Most probably two times, right?
> And what does it do each time?
>
> [snip]
>> void OnGettingNetworkList()
>> {
>> NetworkList netList = getNetworkList();
>> }
>
> You return a *copy* of the NetworkList you build in the function.
> The first copy dies and deallocates via Clear() all the pointers so
> the copy contains invalid pointers, which are deallocated yet again,
> that's where the CString fails it assertions, becuase it is already
> destroyed.
>
yes thanks!!!! I knew it was something like that but I couldn't find it.
How can I solve this ? If I remove my Clear() method how can I be sure
that when netList is destroyed, there is no memory leak ?

void OnGettingNetworkList()
{
NetworkList netList = getNetworkList();
}


Maybe it's a bad idea and I should do something like :

NetworkList netList;
getNetworkList(netList);





>> When the netList is destroyed I get a debug assertion due to CString
>> object :
>>
>> void Release() throw()
>> {
>> ATLASSERT( nRefs != 0 ); <<<<< !!!!!!!!!
>>
>> if( _AtlInterlockedDecrement( &nRefs ) <= 0 ) {
>> pStringMgr->Free( this );
>> }
>> }
>

peter koch

10/24/2008 4:55:00 PM

0

On 24 Okt., 18:14, John Doe <mos...@anonymous.org> wrote:
> Obnoxious User wrote:
> > On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:
>
> >> Victor Bazarov wrote:
> >>> John Doe wrote:
> >> So here is the update code (without the try for new I will do it later)
> >> but now I get an error :
> >> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
> >> 'const NetworkList' to 'NetworkList &'
>
> >> so I have added const to Clear()...
>
> > [snip]
> >>        void Clear()
> >>        {
> >>          for_each( _netlist.begin(), _netlist.end(), DeletePointer());
> >>        }
>
> > How many times is this function called in your test case?
> > Most probably two times, right?
> > And what does it do each time?
>
> > [snip]
> >> void OnGettingNetworkList()
> >> {
> >>     NetworkList netList = getNetworkList();
> >> }
>
> > You return a *copy* of the NetworkList you build in the function.
> > The first copy dies and deallocates via Clear() all the pointers so
> > the copy contains invalid pointers, which are deallocated yet again,
> > that's where the CString fails it assertions, becuase it is already
> > destroyed.
>
> yes thanks!!!! I knew it was something like that but I couldn't find it.
> How can I solve this ? If I remove my Clear() method how can I be sure
> that when netList is destroyed, there is no memory leak ?
>
> void OnGettingNetworkList()
> {
>       NetworkList netList = getNetworkList();
>
> }
>
> Maybe it's a bad idea and I should do something like :
>
> NetworkList netList;
> getNetworkList(netList);
>

I don't see what that would help. What I don't understand is why the
networklist is a list of pointers (typedef std::list<Network*>). It
looks more natural to me to have it as a list of values
(std::list<Network>). This also simplifies your design quite a lot.

/Peter

Obnoxious User

10/24/2008 5:05:00 PM

0

On Fri, 24 Oct 2008 18:14:35 +0200, John Doe wrote:

> Obnoxious User wrote:
>> On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:
>>
>>> Victor Bazarov wrote:
>>>> John Doe wrote:
>>> So here is the update code (without the try for new I will do it
>>> later) but now I get an error :
>>> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
>>> 'const NetworkList' to 'NetworkList &'
>>>
>>> so I have added const to Clear()...
>>>
>>>
>> [snip]
>>> void Clear()
>>> {
>>> for_each( _netlist.begin(), _netlist.end(), DeletePointer());
>>> }
>>>
>>>
>> How many times is this function called in your test case? Most probably
>> two times, right?
>> And what does it do each time?
>>
>> [snip]
>>> void OnGettingNetworkList()
>>> {
>>> NetworkList netList = getNetworkList();
>>> }
>>
>> You return a *copy* of the NetworkList you build in the function. The
>> first copy dies and deallocates via Clear() all the pointers so the
>> copy contains invalid pointers, which are deallocated yet again, that's
>> where the CString fails it assertions, becuase it is already destroyed.
>>
> yes thanks!!!! I knew it was something like that but I couldn't find it.
> How can I solve this ? If I remove my Clear() method how can I be sure
> that when netList is destroyed, there is no memory leak ?
>

You're missing a proper copy constructor.

--
OU
Remember 18th of June 2008, Democracy died that afternoon.
http://frapedia.se/wiki/Information_...

John Doe

10/24/2008 6:06:00 PM

0

Obnoxious User a écrit :
> On Fri, 24 Oct 2008 18:14:35 +0200, John Doe wrote:
>
>> Obnoxious User wrote:
>>> On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:
>>>
>>>> Victor Bazarov wrote:
>>>>> John Doe wrote:
>>>> So here is the update code (without the try for new I will do it
>>>> later) but now I get an error :
>>>> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
>>>> 'const NetworkList' to 'NetworkList &'
>>>>
>>>> so I have added const to Clear()...
>>>>
>>>>
>>> [snip]
>>>> void Clear()
>>>> {
>>>> for_each( _netlist.begin(), _netlist.end(), DeletePointer());
>>>> }
>>>>
>>>>
>>> How many times is this function called in your test case? Most probably
>>> two times, right?
>>> And what does it do each time?
>>>
>>> [snip]
>>>> void OnGettingNetworkList()
>>>> {
>>>> NetworkList netList = getNetworkList();
>>>> }
>>> You return a *copy* of the NetworkList you build in the function. The
>>> first copy dies and deallocates via Clear() all the pointers so the
>>> copy contains invalid pointers, which are deallocated yet again, that's
>>> where the CString fails it assertions, becuase it is already destroyed.
>>>
>> yes thanks!!!! I knew it was something like that but I couldn't find it.
>> How can I solve this ? If I remove my Clear() method how can I be sure
>> that when netList is destroyed, there is no memory leak ?
>>
>
> You're missing a proper copy constructor.
>
Finally I am using getNetworkList like this :

void getNetworkList(NetworkList& netList)
{
....
}


getNetworkList(m_NetworkList);
and now it works fine.


However now that I have added const everywhere I cannot even do this :

CString strTmp = pNetwork->getName();
or LPCTSTR szName = pNetwork->getName();




That's why I think const brings more issues than it solves ...









John Doe

10/24/2008 6:13:00 PM

0

Mosfet a écrit :
> Obnoxious User a écrit :
>> On Fri, 24 Oct 2008 18:14:35 +0200, John Doe wrote:
>>
>>> Obnoxious User wrote:
>>>> On Fri, 24 Oct 2008 17:18:15 +0200, John Doe wrote:
>>>>
>>>>> Victor Bazarov wrote:
>>>>>> John Doe wrote:
>>>>> So here is the update code (without the try for new I will do it
>>>>> later) but now I get an error :
>>>>> error C2662: 'NetworkList::Clear' : cannot convert 'this' pointer from
>>>>> 'const NetworkList' to 'NetworkList &'
>>>>>
>>>>> so I have added const to Clear()...
>>>>>
>>>>>
>>>> [snip]
>>>>> void Clear()
>>>>> {
>>>>> for_each( _netlist.begin(), _netlist.end(), DeletePointer());
>>>>> }
>>>>>
>>>>>
>>>> How many times is this function called in your test case? Most probably
>>>> two times, right?
>>>> And what does it do each time?
>>>>
>>>> [snip]
>>>>> void OnGettingNetworkList()
>>>>> {
>>>>> NetworkList netList = getNetworkList();
>>>>> }
>>>> You return a *copy* of the NetworkList you build in the function. The
>>>> first copy dies and deallocates via Clear() all the pointers so the
>>>> copy contains invalid pointers, which are deallocated yet again, that's
>>>> where the CString fails it assertions, becuase it is already destroyed.
>>>>
>>> yes thanks!!!! I knew it was something like that but I couldn't find it.
>>> How can I solve this ? If I remove my Clear() method how can I be sure
>>> that when netList is destroyed, there is no memory leak ?
>>>
>>
>> You're missing a proper copy constructor.
>>
> Finally I am using getNetworkList like this :
>
> void getNetworkList(NetworkList& netList)
> {
> ...
> }
>
>
> getNetworkList(m_NetworkList);
> and now it works fine.
>
>
> However now that I have added const everywhere I cannot even do this :
>
> CString strTmp = pNetwork->getName();
> or LPCTSTR szName = pNetwork->getName();
>
>
>
>
> That's why I think const brings more issues than it solves ...

YHum sorry with the full code it's better :

const Network* pNetwork = m_NetworkList.getNetwork(lpAttrVal);
const CString& strTmp = pNetwork->getName();

I get :

error C2662: 'Network::getName' : cannot convert 'this' pointer from
'const Network' to 'Network &'

peter koch

10/24/2008 6:15:00 PM

0

On 24 Okt., 20:05, Mosfet <mos...@anonymous.org> wrote:
> Obnoxious User a écrit :
>
>
>
> > On Fri, 24 Oct 2008 18:14:35 +0200, John Doe wrote:
>
> >> Obnoxious User wrote:

[snip]
>
> >>> How many times is this function called in your test case? Most probably
> >>> two times, right?
> >>> And what does it do each time?
>
> >>> [snip]
> >>>> void OnGettingNetworkList()
> >>>> {
> >>>>     NetworkList netList = getNetworkList();
> >>>> }
> >>> You return a *copy* of the NetworkList you build in the function. The
> >>> first copy dies and deallocates via Clear() all the pointers so the
> >>> copy contains invalid pointers, which are deallocated yet again, that's
> >>> where the CString fails it assertions, becuase it is already destroyed.
>
> >> yes thanks!!!! I knew it was something like that but I couldn't find it.
> >> How can I solve this ? If I remove my Clear() method how can I be sure
> >> that when netList is destroyed, there is no memory leak ?
>
> > You're missing a proper copy constructor.
>
> Finally I am using getNetworkList like this :
>
> void getNetworkList(NetworkList& netList)
> {
> ...
>
> }
>
> getNetworkList(m_NetworkList);
> and now it works fine.

No it isn't. Not unless you do a fair deal of work in the function (a
deep copy), and in that case, you might just as well have followed my
advice in the first place.
>
> However now that I have added const everywhere I cannot even do this :
>
> CString strTmp = pNetwork->getName();
> or LPCTSTR szName = pNetwork->getName();
>
> That's why I think const brings more issues than it solves ...

That is because you have put your consts in the wrong places or
because CString is broken with respect to constness - I don't really
know that class. Why dount you simply use std::wstring?

/Peter

John Doe

10/24/2008 6:32:00 PM

0

peter koch a écrit :
> On 24 Okt., 20:05, Mosfet <mos...@anonymous.org> wrote:
>> Obnoxious User a écrit :
>>
>>
>>
>>> On Fri, 24 Oct 2008 18:14:35 +0200, John Doe wrote:
>>>> Obnoxious User wrote:
>
> [snip]
>>>>> How many times is this function called in your test case? Most probably
>>>>> two times, right?
>>>>> And what does it do each time?
>>>>> [snip]
>>>>>> void OnGettingNetworkList()
>>>>>> {
>>>>>> NetworkList netList = getNetworkList();
>>>>>> }
>>>>> You return a *copy* of the NetworkList you build in the function. The
>>>>> first copy dies and deallocates via Clear() all the pointers so the
>>>>> copy contains invalid pointers, which are deallocated yet again, that's
>>>>> where the CString fails it assertions, becuase it is already destroyed.
>>>> yes thanks!!!! I knew it was something like that but I couldn't find it.
>>>> How can I solve this ? If I remove my Clear() method how can I be sure
>>>> that when netList is destroyed, there is no memory leak ?
>>> You're missing a proper copy constructor.
>> Finally I am using getNetworkList like this :
>>
>> void getNetworkList(NetworkList& netList)
>> {
>> ...
>>
>> }
>>
>> getNetworkList(m_NetworkList);
>> and now it works fine.
>
> No it isn't. Not unless you do a fair deal of work in the function (a
> deep copy), and in that case, you might just as well have followed my
> advice in the first place.
If I knew what you mean I won't be posting here
Maybe it doesn't work but my application seems ok!
I forgot to say now getNetworkList is now declared to take a reference
on a NetworkList so there is no copy anymore.
:
void getNetworkList(NetworkList& netList)
{
GUID guid;
netList.Add(new Network(_T("Network1"), guid));
netList.Add(new Network(_T("Network2"), guid));
}

>> However now that I have added const everywhere I cannot even do this :
>>



>> CString strTmp = pNetwork->getName();
>> or LPCTSTR szName = pNetwork->getName();
>>
>> That's why I think const brings more issues than it solves ...
>
> That is because you have put your consts in the wrong places or
> because CString is broken with respect to constness - I don't really
> know that class. Why dount you simply use std::wstring?
>
> /Peter
Same issue with std::wstring..

const Network* pNetwork = m_NetworkList.getNetwork(lpAttrVal);
const std::wstring& strTmp = pNetwork->getName();

error C2662: 'Network::getName' : cannot convert 'this' pointer from
'const Network' to 'Network &'