My C++ has gotten so rusty!!!
If my constructor looks like this:
Image2D::Image2D(LPDIRECT3DDEVICE9 device)
:
SceneObject2D(device),
<snip>
How do I do my copy constructor...I am not sure how to initialize the
base outside of the initializer list..
Image2D::Image2D(const Image2D & rhs)
:
m_path(rhs.m_path),
m_rows(rhs.m_rows),
m_cols(rhs.m_cols),
m_transparent(rhs.m_transparent),
m_active(rhs.m_active),
m_numFrames(rhs.m_numFrames),
m_currentFrame(rhs.m_currentFrame),
m_position(rhs.m_position),
m_depth(rhs.m_depth),
m_width(rhs.m_width),
m_height(rhs.m_height)
{
if(rhs.m_device)
{
rhs.m_device->AddRef();
// Is this the way to construct my base or is it
// contructing something that never gets used???
SceneObject2D(rhs.m_device);
}
} 1 1546
brekehan wrote:
My C++ has gotten so rusty!!!
If my constructor looks like this:
Image2D::Image2D(LPDIRECT3DDEVICE9 device)
:
SceneObject2D(device),
<snip>
How do I do my copy constructor...I am not sure how to initialize the
base outside of the initializer list..
You don't. You initialize it in the initializer list.
Image2D::Image2D(const Image2D & rhs)
:
m_path(rhs.m_path),
m_rows(rhs.m_rows),
m_cols(rhs.m_cols),
m_transparent(rhs.m_transparent),
m_active(rhs.m_active),
m_numFrames(rhs.m_numFrames),
m_currentFrame(rhs.m_currentFrame),
m_position(rhs.m_position),
m_depth(rhs.m_depth),
m_width(rhs.m_width),
m_height(rhs.m_height)
{
if(rhs.m_device)
{
rhs.m_device->AddRef();
// Is this the way to construct my base or is it
// contructing something that never gets used???
SceneObject2D(rhs.m_device);
It creates a temporary SceneObject2D that is destroyed immediately
afterwards. As soon as you enter the consturctor body, base class part and
member variable initialization is finised.
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Edward Diener |
last post by:
Coming from the C++ world I can not understand the reason why copy
constructors are not used in the .NET framework. A copy constructor creates
an object from a copy of another object of the same...
|
by: Bryan Bullard |
last post by:
i have a class that contains a private pointer to a system resource. i'm
quite sure that i will need to have a user defined copy-constructor to do a
deep copy. can someone put me in the right...
|
by: trying_to_learn |
last post by:
Why do we need to explicitly call the copy constructor and the operator
= , for base class and member objects in composition?
....book says "You must explicitly call the GameBoard copy-constructor...
|
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using...
|
by: Josef Meile |
last post by:
Hi,
I have this constructor:
public CExcelDatabase(string host, string user, string password, string
database,
bool promptCredentials, int
findExcelInstance, bool readOnly)
{
//Some code...
|
by: Andrew Schepler |
last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
|
by: JurgenvonOerthel |
last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and
Derived2 derive publicly from Base.
Given a 'const Base &input' I want to initialize a 'const Derived1
&output'.
If the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |