Hello all,
I came across the following definition (or is it declaration? I
never know):
struct OFFSET_AND_SIZE
{
INT64 offset;
UINT64 size;
OFFSET_AND_SIZE (INT64 o, UINT64 s) : offset (o), size (s) {}
};
(INT64 are UINT64 are not relevant to the discussion.)
I know some C, but very little C++ so I was somewhat puzzled. Is the
function inside the struct a constructor which will assign o to
offset and s to size?
So, I would write struct OFFSET_AND_SIZE toto(666, 999); and toto's
fields would be initialized as I expect, right?
What if I write struct OFFSET_AND_SIZE toto; would the compiler
complain, or would the fields remain undefined, as in C? 2 5937
"Grumble" <in*****@kma.eu.org> wrote in message news:br**********@news-rocq.inria.fr... Hello all,
I came across the following definition (or is it declaration? I never know):
It's a definition. I know some C, but very little C++ so I was somewhat puzzled. Is the function inside the struct a constructor
It is a constructor. structs are the classes in C++, they can have constructors.
The only difference is the access control is public by default in struct.
which will assign o to offset and s to size?
More correctly, it will initialize o and s with those values. So, I would write struct OFFSET_AND_SIZE toto(666, 999); and toto's fields would be initialized as I expect, right?
Yes.
What if I write struct OFFSET_AND_SIZE toto; would the compiler complain, or would the fields remain undefined, as in C?
It will complain. Once you declare ANY constructor, the implicit
default constructor is gone. Your class has no default constructor
so you can't initalize
Ron Natalie wrote:
<snip>
Thank you, Ron. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: thecrow |
last post by:
I am trying to pass a connected db link into a class constructor. In
the calling module, the link opens successfully and passes the
is_resource test. If I pass the same link into a class...
|
by: Daniel |
last post by:
Hello =)
I have an object which contains a method that should execute every x ms. I
can use setInterval inside the object construct like this -
self.setInterval('ObjectName.methodName()',...
|
by: Vince |
last post by:
I recently learned that it's possible to put a constructor inside a struct.
My question is : Is it possible to do the following :
typedef struct _TRecInfo
{
_TRecInfo(int nKey, int nMode):...
|
by: Marcus Kwok |
last post by:
Is it in the standard that one cannot declare a member of a struct that
uses a non-default constructor? Here is my simplified code; the Matrix
class was taken from the FAQ, and works well...
|
by: Carl Rosenberger |
last post by:
Hi all,
I would like to create an instance of a struct with
reflection.
The way I am used to doing this with classes:
- get a ConstructorInfo from the Type
- call Invoke()
However, if a...
|
by: gopal |
last post by:
Can one constructor of a class call another constructor of the same
class to initialize the this object?
I read in the FAQ , to the above question the following ans was given
Nope.
Let's...
|
by: silversurfer2025 |
last post by:
Hello everybody,
I had this problem several times now and did not yet get the reasoning
behind it. I have a class with a pointer as member variable, lets say a
float array. Furthermore, I have two...
|
by: sachinc.biradar |
last post by:
Hi,
I am pretty new to C++, I have following doubt.
Why can't we pass an argument to constructor as pointer? As per my
knowledge referance is like const pointer.
Any help will be highly...
|
by: =?ISO-8859-1?Q?Konrad_M=FChler?= |
last post by:
Hi,
I've a struct:
struct POINT {
int x,y;
};
And I want to commit a variable of type POINT in a function
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |