I have to work on a rather big project that a bunch of people wrote and
that has no useful documentation at all, my C++ has rusted in a bit,
now I stumbled over a constructor that looks something like the below
and have no idea what to do with it :)
inheritedClass: :inheritedClass ([...bunch of arguments...])
: originalConstru ctor ([...bunch of arguments...])
, m_cells(cells), m_srfcs(srfcs)
{
[... some code ...]
}
Now my problem is that I have no clue what the comma-separated
arguments(?) m_cells and m_srfcs do in this method definition. Is
anyone able to enlighten me what this syntax is good for?
Besides not knowing what those arguments do, I must know wether this
usage of the two class instances (m_cells and m_srfcs are instances of
2 classes) would call their constructor, because in that case I would
need to modify the argument passed to them.
I would simply test this, but the project is just too big and there are
too many changes that I have to do at once before I can do a test
compilation and check it's runtime behaviour.
Any help is appreciated :)
Regards,
Lars Uffmann 20 3234
lars.uffm...@rw th-aachen.de wrote: I have to work on a rather big project that a bunch of people wrote and that has no useful documentation at all, my C++ has rusted in a bit, now I stumbled over a constructor that looks something like the below and have no idea what to do with it :)
inheritedClass: :inheritedClass ([...bunch of arguments...]) : originalConstru ctor ([...bunch of arguments...]) , m_cells(cells), m_srfcs(srfcs) { [... some code ...] }
Now my problem is that I have no clue what the comma-separated arguments(?) m_cells and m_srfcs do in this method definition. Is anyone able to enlighten me what this syntax is good for?
http://www.parashift.com/c++-faq-lit....html#faq-10.6
Besides not knowing what those arguments do, I must know wether this usage of the two class instances (m_cells and m_srfcs are instances of 2 classes) would call their constructor, because in that case I would need to modify the argument passed to them.
Yes, that syntax calls the constructors for m_cells and m_srfcs
Gavin Deane la**********@rw th-aachen.de wrote: I have to work on a rather big project that a bunch of people wrote and that has no useful documentation at all, my C++ has rusted in a bit,
I doubt that this is a good idea. You seem not to be qualified for this.
now I stumbled over a constructor that looks something like the below and have no idea what to do with it :)
inheritedClass: :inheritedClass ([...bunch of arguments...]) : originalConstru ctor ([...bunch of arguments...]) , m_cells(cells), m_srfcs(srfcs) { [... some code ...] }
Now my problem is that I have no clue what the comma-separated arguments(?) m_cells and m_srfcs do in this method definition. Is anyone able to enlighten me what this syntax is good for?
m_cells and m_srfcs are members variables of inheritedClass. The above
initializes theese varibles with the values 'cells' and 'srfcs'.
This is a very basic idiom. You should refer to your Stroustrup (chapter
10.4.6) or other textbook of your choice to read about it.
Besides not knowing what those arguments do, I must know wether this usage of the two class instances (m_cells and m_srfcs are instances of 2 classes) would call their constructor, because in that case I would need to modify the argument passed to them.
I would simply test this, but the project is just too big and there are too many changes that I have to do at once before I can do a test compilation and check it's runtime behaviour.
No need to change the project. Just create a very small sandbox project
with just one file to explore the syntax and behaviour of this idiom.
Gabriel
Any help is appreciated :)
Regards,
Lars Uffmann la**********@rw th-aachen.de wrote:
Btw, I'm just curious: At which institute do you work?
Gabriel I have to work on a rather big project that a bunch of people wrote and that has no useful documentation at all, my C++ has rusted in a bit, now I stumbled over a constructor that looks something like the below and have no idea what to do with it :)
inheritedClass: :inheritedClass ([...bunch of arguments...]) : originalConstru ctor ([...bunch of arguments...]) , m_cells(cells), m_srfcs(srfcs) { [... some code ...] }
Now my problem is that I have no clue what the comma-separated arguments(?) m_cells and m_srfcs do in this method definition. Is anyone able to enlighten me what this syntax is good for?
Besides not knowing what those arguments do, I must know wether this usage of the two class instances (m_cells and m_srfcs are instances of 2 classes) would call their constructor, because in that case I would need to modify the argument passed to them.
I would simply test this, but the project is just too big and there are too many changes that I have to do at once before I can do a test compilation and check it's runtime behaviour.
Any help is appreciated :)
Regards,
Lars Uffmann la**********@rw th-aachen.de wrote: I have to work on a rather big project that a bunch of people wrote and that has no useful documentation at all, my C++ has rusted in a bit, now I stumbled over a constructor that looks something like the below and have no idea what to do with it :)
inheritedClass: :inheritedClass ([...bunch of arguments...]) : originalConstru ctor ([...bunch of arguments...]) , m_cells(cells), m_srfcs(srfcs) { [... some code ...] }
Now my problem is that I have no clue what the comma-separated arguments(?) m_cells and m_srfcs do in this method definition. Is anyone able to enlighten me what this syntax is good for?
Besides not knowing what those arguments do, I must know wether this usage of the two class instances (m_cells and m_srfcs are instances of 2 classes) would call their constructor, because in that case I would need to modify the argument passed to them.
I would simply test this, but the project is just too big and there are too many changes that I have to do at once before I can do a test compilation and check it's runtime behaviour.
Any help is appreciated :)
Regards,
Lars Uffmann
the comma separated arguments m_cells and m_srcs are initialization
constructs for those variables of that class.
those constructs call the corresponding constructors depending on the
type of arguments.
> m_cells and m_srfcs are members variables of inheritedClass. The above initializes theese varibles with the values 'cells' and 'srfcs'.
Thank you - I've had a chance to talk with my "boss" at the institute
in between and that is the information I was looking for, he said the
same :)
For a moment I was wondering why the initialization isn't done in the
inherited Constructor, but that is because then the properly
initialized member variables would NOT be available for the original
constructor to be handled. Either way, this option of initializing
member variables was completely new to me :)
No need to change the project. Just create a very small sandbox project with just one file to explore the syntax and behaviour of this idiom.
TBH, I only started working with Linux again when I was assigned to
this project, and while I am quite comfortable with producing quality
C++ code, I am not so familiar with the gnu compiler and makefiles yet
:)
I'll have to experiment a bit before I get a test project running I
guess, just been to lazy to do that yet.
Btw, I'm just curious: At which institute do you work?
Institute of Aerodynamics - we're working on a numerical flow solver,
my job is to merge two versions that have been modified by different
people without the use of a CVS, and later to port the flow solver for
usage on a cluster system (simultaneous computing).
Regards,
Lars Uffmann
btw thank you for the parashift link, Gavin, that sort of covered all
questions I had left about the initialization list :)
Except that I am still not sure wether this calls the constructors of
m_cells and m_srfcs. Because the call m_cells(cells) just initializes
the class, and (cells) is not an argument for m_cells constructor, but
rather an object of the same type as m_cells.
Either way, my main question is answered - I do not need to modify the
code in this case at all :)
Regards,
Lars Uffmann la**********@rw th-aachen.de wrote: btw thank you for the parashift link, Gavin, that sort of covered all questions I had left about the initialization list :) Except that I am still not sure wether this calls the constructors of m_cells and m_srfcs. Because the call m_cells(cells) just initializes the class, and (cells) is not an argument for m_cells constructor, but rather an object of the same type as m_cells.
Either way, my main question is answered - I do not need to modify the code in this case at all :)
Regards,
Lars Uffmann
in such case it calls the copy constructor of the of the m_cells
objects' class.
Copy constructor is a default constructor that exists for each object
that you create? Basically doing a memory copy of (cells) and
positioning the object pointer m_cells on that memory?
Regards,
Lars Uffmann la**********@rw th-aachen.de wrote: Copy constructor is a default constructor that exists for each object
.....each class that you create? Basically doing a memory copy of (cells) and positioning the object pointer m_cells on that memory?
Regards,
Lars Uffmann
Yup, that's right. You should be careful with this one. if your class
contains any pointers or contains classes containing pointers or
(recurse this), you are about to crash, since the data is not copied
recursively. In theese cases you should either write the copy
constructor or explicitly deactive it.
You can use this idiom to make the copy constructor inaccesible:
class Blob{
private: Blob& Blob(const Blob&);
// other stuff
};
--
Who is General Failure and why is he reading my hard disk? 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 kind. It sounds simple
but evidently .NET has difficulty with this concept for some reason. I do
understand that .NET objects are created on the GC heap but that doesn't
mean that they couldn't be copied from another object of the same kind when...
|
by: SLE |
last post by:
Hi there,
I know constructors are not inherited from the base class, not in VB.NET nor
C# (nor Java I suppose). I never wondered,but reflecting on the reason why,
I cannot find a solid answer.
Is the reason technical (compiler or CLR limitation) or logical (OOP best
practices)?
Any feedback would be greatly appreciated.
|
by: Doug |
last post by:
I have a public abstract class that I want to inherit from in two other
classes. My public abstract one has a constructor with several
parameters. For some reason I cannot get to that constructor unless I
create a constructor in my two other classes like this:
public ClassName(string szParameter1, string szParameter2, string
szParameter3) : base(szParameter1, szParameter2, szParameter3)
{
}
|
by: Alexander Muylaert |
last post by:
Hi
Is their a way to keep constructors visible in inherited classes?
public class X{
public x(int A){}
}
public class Y : X{};
|
by: Michael Hull |
last post by:
Hi,
I remember from somewhere reading that inlining constructors is a
'BadThing', but now can't seem to find the original source. I can't
however thing of a reason why it would be for simple constructors...
any thoughts
Mike
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |