Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 10-01-2008, 05:32 AM   #1 (permalink)
 
Newb Techie

Join Date: Oct 2008

Posts: 1

sargeMonkey is on a distinguished road

Default C++

Hi,

I got asked this question in an interview: How do you create a copy constructor for a int * ?
Is this a valid question? Is it possible to create a copy constructor for a int *?
sargeMonkey is offline  
Old 10-01-2008, 07:02 AM   #2 (permalink)
S0ULphIRE's Avatar
 
01001100011011110110110

Join Date: Mar 2007

Location: Perth, Australia

Posts: 1,940

S0ULphIRE has a spectacular aura aboutS0ULphIRE has a spectacular aura about

Send a message via MSN to S0ULphIRE
Default Re: C++

wouldn't it just be the same as a normal copy constructor, only using the pointer to store the memory address of your usual variable?

copy constructors
copy constructors2
constructors3

I'm sorta new to this 'copy constructor' idea, so I don't really know if I'm spouting rubbish Take a look at those links, maybe one will help.

__________________
"As a result of all this hardship, dirt, thirst, and wombats, you would expect Australians to be a dour lot. Instead, they are genial, jolly, cheerful, and always willing to share a kind word with a stranger, unless they are an American."
-- Douglas Adams

Click this if I helped you
>>>><<<<
S0ULphIRE is offline  
Old 10-01-2008, 09:33 PM   #3 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: C++

Well you can either store the value that the pointer is pointing to or you can store the address in memory which is the actual value of the pointer.

A basic copy constructor for an int* is simple. Assuming the class has already been made and called cstr and it has a private member int* intptr the code is as follows:

Code:
cstr::cstr(int* inpt)
{
	intptr = inpt;
}
I think that's what you're trying to ask but correct me if it's not.
__________________

Baez is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On