Solved

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

Posted on 2012-03-29
4
291 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unresolved External Symbols 3 102
mapAB Challlenge 35 155
Need some help with Microsoft Visual Studio C++ 2003 5 63
Problem to Alipay 10 42
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

809 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