Copy contructor with argument

I am doing some mistake in creating copy constructor with argument. Please help me to resolve the issue.

I wanted to have a copy of "oldClientInfo" object in "clientInfo". Both of type ClientInfo. But the values are not reflecting in object after using copy constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Normal constructor
ClientInfo::ClientInfo(Listener& listener)
:msgId(0),
pId(0),
timeout(0),
gracePeriod(0),
eventSeverity(0),
timer(listener)
{
}

// usage 
Listener& listener;
ClientInfo clientInfo(listener);

/******************************************/
PROBLEM in copy constructor:
ClientInfo::ClientInfo(ClientInfo& clientInfo, Listener& listener)
:timer(listener)
{
    msgId = clientInfo.msgId;
    pId = clientInfo.pId;
    timeout = clientInfo.timeout;
    gracePeriod = clientInfo.gracePeriod;
    eventSeverity = clientInfo.eventSeverity;
}

// usage
Listener& listener;
ClientInfo clientInfo(oldClientInfo, listener);
/******************************************/


In what way are they 'off'?

How about normal copy construction and then update of the timer?

What are those uninitialized Listener references anyway?
Listener& listener;

Listener listener; // It not an reference my typo error

timeout callback function is implemented when the timer expires.

I AM VERY SURE THERE IS SOME PROBLEM BECAUSE OF copying TIMER.
When timer expires callback of listener is called.

And i need a new listener passed to copy constructor.
What does this have to do with ClientInfo? Constructor of 'timer' and nature of Listener are much more involved (and unknown to us).
Hi freind i think the definition is correct there was some basic mistake i was doing in my code. Was passing a local object clientInfo and storing the pointer.

Please just confirm the syntax i have written for copy constructor is correct.

I would be closing the post after your reply 2 solved :)
It is ok, but not really a "copy", because timer won't be a copy of clientInfo.timer.

See http://www.cplusplus.com/articles/y8hv0pDG/
for the syntax used by compiler-generated copy constructor.
Topic archived. No new replies allowed.