Hello everyone,
I am using a struct inside another class, which can be used through an
empty constructor or another one. The definition looks like this:
struct Entry{
int index; //line 38
FeatureVector* value; //line 39
int object;
int count;
double variance;
Entry() {}
Entry(FeatureVector* _value, int _index, int _object, int _count,
double _variance)
: value(_value), index(_index), object(_object), count(_count),
variance(_variance) {}
};
When I am compiling I get the following error:
.../ModelContainer.h: In constructor 'Entry::Entry(FeatureVector*,
int, int, int, double)':
.../ModelContainer.h:39: warning: 'Entry::value' will be initialized
after
.../ModelContainer.h:38: warning: 'int Entry::index'
.../ModelContainer.h:44: warning: when initialized here
Why this? isn't it only initialized on calling the second constructor?
This should be no problem to me so why the warning?
Thanks a lot for your help
Tim 4 2069
"silversurfer2025" <ki****@web.dewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hello everyone,
I am using a struct inside another class, which can be used through an
empty constructor or another one. The definition looks like this:
struct Entry{
int index; //line 38
FeatureVector* value; //line 39
int object;
int count;
double variance;
Entry() {}
Entry(FeatureVector* _value, int _index, int _object, int _count,
double _variance)
: value(_value), index(_index), object(_object), count(_count),
variance(_variance) {}
};
When I am compiling I get the following error:
../ModelContainer.h: In constructor 'Entry::Entry(FeatureVector*,
int, int, int, double)':
../ModelContainer.h:39: warning: 'Entry::value' will be initialized
after
../ModelContainer.h:38: warning: 'int Entry::index'
../ModelContainer.h:44: warning: when initialized here
Why this? isn't it only initialized on calling the second constructor?
This should be no problem to me so why the warning?
There's no problem. The warning is just to let you know that you put the
initializer for value before the initializer for index, but because index is
declared before value in the class, it will get initialized first.
Initializations occur in order of their declaration in the class.
(Personally, I'd disable that particular warning, if possible.)
-Howard
I recommend reordering the initializer list to conform the declaration
order.
This is the recommended practice rather than turning off the compiler
warning in my opinion.
Tolga Ceylan
There's no problem. The warning is just to let you know that you put the
initializer for value before the initializer for index, but because index is
declared before value in the class, it will get initialized first.
Initializations occur in order of their declaration in the class.
(Personally, I'd disable that particular warning, if possible.)
-Howard
<to***********@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
>
[please don't top-post. re-ordered]
>
>There's no problem. The warning is just to let you know that you put the initializer for value before the initializer for index, but because index is declared before value in the class, it will get initialized first. Initializations occur in order of their declaration in the class. (Personally, I'd disable that particular warning, if possible.)
I recommend reordering the initializer list to conform the declaration
order.
This is the recommended practice rather than turning off the compiler
warning in my opinion.
Yeah, that's probably a better option. (Not that it affects the resulting
binaries one way or the other, of course. :-))
-Howard
Howard schrieb:
<to***********@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
[please don't top-post. re-ordered]
There's no problem. The warning is just to let you know that you put the
initializer for value before the initializer for index, but because index
is
declared before value in the class, it will get initialized first.
Initializations occur in order of their declaration in the class.
(Personally, I'd disable that particular warning, if possible.)
I recommend reordering the initializer list to conform the declaration
order.
This is the recommended practice rather than turning off the compiler
warning in my opinion.
Oh, now I get the error,.. I simply did not think of this as being
warnable at all, but one never stops learning... Switched index and
value and everything is fine now..
Thanks
Tim
Yeah, that's probably a better option. (Not that it affects the resulting
binaries one way or the other, of course. :-))
-Howard
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter van der Goes |
last post by:
When a struct is created in C# and a parameterized constructor defined, the
IntelliSense editor shows only the syntax for the parameterized constructor
in tooltips, but not for the default...
|
by: Wellu Mäkinen |
last post by:
Hi all,
let's say I have a need to store 4 int values in somekind
of a structure. I have atleast two options:
class A
{
public:
int a, b, c, b;
|
by: fix |
last post by:
Hi all,
I feel unclear about what my code is doing, although it works but I am
not sure if there is any possible bug, please help me to verify it.
This is a trie node (just similar to tree nodes)...
|
by: Russell Shaw |
last post by:
Hi,
I have two structs in a header file, and they reference each other,
causing a compile error. Is there a standard way to deal with this?
typedef struct {
...
RtAction *actions;
}...
|
by: Sven Groot |
last post by:
This was posted by someone in comp.lang.c++, and later in
microsoft.public.vstudio.general, but since I know Carl is in this group,
and he's the one that should read this, I've reposted it here....
|
by: Karl M |
last post by:
Hi everyone,
I just notice some strange behaviors on the MS C++ compiler regarding struct
default constructor, see the example bellow:
struct MyStruct
{
int a;
};
class MyClass
{
public:
|
by: JohnGoogle |
last post by:
Hi,
Newbie question...
After a recent article in VSJ I had a go at implementing a Fraction
class to aid my understanding of operator overloading. After a previous
message someone suggested...
|
by: Zytan |
last post by:
I have a struct constructor to initialize all of my private (or public
readonly) fields. There still exists the default constructor that sets
them all to zero. Is there a way to remove the...
|
by: Bill |
last post by:
Hello All,
I am trying to pass a struct to a function. How would that best be
accomplished?
Thanks,
Bill
|
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: 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: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
|
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...
| |