Solved

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

Posted on 2012-03-29
4
288 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
Comment Utility
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
Comment Utility
AClass*   ptrAClassInst =  new AClass();
AClass   anotherClassInst;

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

Expert Comment

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

Author Closing Comment

by:prain
Comment Utility
Oops sorry. My mistake. This is good. Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 102
fix34  challenge 9 95
count11 challenge 6 46
Arduino EDI - Programming language 3 59
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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now