Solved

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

Posted on 2012-03-29
4
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path to  STL Map header file 1 91
Way to decrease size of apk file 9 132
Gaming Software 1 39
MFC COM Server not showing  form 4 27
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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