Solved

How to copy a poiner type to a regular static object in C++

Posted on 2012-03-29
4
290 Views
Last Modified: 2012-03-29
I have a class..

class AClass {};

I define:

AClass*   ptrAClassInst =  new AClass();
...

AClass   anotherClassInst;

I want to copy the contents of the object pointed to by ptrAClassInst to anotherClassInst.

How?
0
Comment
Question by:prain
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 37782937
Given that the compiler-generated copy constructor is sufficiant:

anotherClassInst = *ptrAClassInst;

Open in new window


If not, you'll have to supply your own, see http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html
0
 

Author Comment

by:prain
ID: 37782997
AClass*   ptrAClassInst =  new AClass();
AClass   anotherClassInst;

anotherClassInst =  *ptrAClassInst ;    //Does not work.
0
 
LVL 86

Expert Comment

by:jkr
ID: 37783081
"Does not work." translates to what kind of error message?
0
 

Author Closing Comment

by:prain
ID: 37783549
Oops sorry. My mistake. This is good. Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 80
countHi2 challenge 7 55
Unable to start eclipse ? 17 141
How to properly read C++ console input into several variables with scanf 2 12
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
This video teaches viewers about errors in exception handling.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question