I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class,
what is the default assuming I don't do anything with it?
For example
class Foo
{
public:
Days week;
};
If I instantiate a Foo object, what is the default of week? Is there
any possibility (perhaps compiler dependent) that if I created and
destroyed Foo objects at an interval of less than 1 second, could
value of week change?
So for talking purposes say I have...
int main()
{
for (int i = 0; i < 10000; ++i) {
Foo *f = new Foo;
cout << f->week << endl;
delete f;
}
Will I get 10000 lines of 0? 7 16962
Travis wrote:
I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class,
what is the default assuming I don't do anything with it?
For example
class Foo
{
public:
Days week;
};
If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
--
Ian Collins.
On May 8, 4:12*pm, Ian Collins <ian-n...@hotmail.comwrote:
Travis wrote:
I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class,
what is the default assuming I don't do anything with it?
For example
class Foo
{
public:
Days week;
};
If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
--
Ian Collins.
Ah ha! That's what I was suspecting. Could you point me to any
documentation on that fact? I'm trying to find stuff and not having
much luck.
On May 8, 4:12*pm, Ian Collins <ian-n...@hotmail.comwrote:
Travis wrote:
I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class,
what is the default assuming I don't do anything with it?
For example
class Foo
{
public:
Days week;
};
If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
--
Ian Collins.
Ah ha! That's what I was suspecting. Could you point me to any
documentation on that fact? I'm trying to find stuff and not having
much luck.
Travis wrote:
On May 8, 4:12 pm, Ian Collins <ian-n...@hotmail.comwrote:
>Travis wrote:
>>I'm curious, if you have an enum say... enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; I understand the default will be Mon=0, Tue=1, Wed=2, etc. What I'm curious about is if there is a Days attribute in a class, what is the default assuming I don't do anything with it? For example class Foo { public: Days week; }; If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
[please don't quote signatures]
>
Ah ha! That's what I was suspecting. Could you point me to any
documentation on that fact? I'm trying to find stuff and not having
much luck.
An enum variable is just like any other, the same initialisation rules
apply to an enum member as apply to on integer member.
I think you are confusing the initialisation of an instance of an enum
and the default values of enum enumerators (the enum constants).
--
Ian Collins.
Ian Collins dixit:
Travis wrote:
>I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class, what is the default assuming I don't do anything with it?
For example
class Foo { public: Days week; };
If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
Static ("global") variable are default initialize (int for example is 0)
Is it undefined even if it is part of a global object ? For example in:
main.cc:
--------
class A {
Days d;
};
A globalA;
int main() {}
brno wrote:
Ian Collins dixit:
>Travis wrote:
>>I'm curious, if you have an enum say...
enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
I understand the default will be Mon=0, Tue=1, Wed=2, etc.
What I'm curious about is if there is a Days attribute in a class, what is the default assuming I don't do anything with it?
For example
class Foo { public: Days week; };
If I instantiate a Foo object, what is the default of week?
Unless you initialise it, the value is undefined.
Static ("global") variable are default initialize (int for example is 0)
Is it undefined even if it is part of a global object ? For example in:
main.cc:
--------
class A {
Days d;
};
A globalA;
The contents of a will be zero initialised. OK for Days in this case,
but not a lot of use for
enum Days { Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun };
--
Ian Collins.
On May 10, 1:39*am, brno <brno.barutc...@gmail.comwrote:
>
Static ("global") variable are default initialize (int for example is 0)
Is it undefined even if it is part of a global object ? For example in:
main.cc:
--------
class A {
* * *Days d;
};
A globalA;
int main() {}
No, global objects are always zero-initialized (before any dynamic
initialization is performed). So in example above, globalA.d will have
the value zero.
Greg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dumboo |
last post by:
hi there,
i was looking for some way to give default values to enum, when ever i m
creating an enum variable it shuld be INITIALIZED to certain default values
is it possible ? or do i have to...
|
by: Vaclav Haisman |
last post by:
Motivation:
I have been working on some project recently that uses lots of enums with
disjunctive intervals of values because it is rather convenient way to
define series of constants with...
|
by: Richard |
last post by:
Okay gang,
This should be simple but apparently it's not... I want
to use the System.DayOfWeek enum to create and access an
array of objects with one object for each day of the
week. I'd like...
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
I have created an enum list like this:
enum myEnum : int
{
This = 2,
That,
NewVal = 10,
LastItm
|
by: Scott Liu |
last post by:
HI, All,
I have a web service doing a string search. It has an operator and a
searchValue field. The operator is defined as an attribute and required. The
xml is as below.
<!--...
|
by: veerleverbr |
last post by:
Suppose having define an enum like this:
public enum SomeEnum
{
Something,
SomethingElse
}
|
by: ASP Developer |
last post by:
I have a web service that returns a class when a web method is called. This
class has a enum property with four values. These four values have default
numbers. For example,
Apple = 5
Orange...
|
by: Peted |
last post by:
I have the following code
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
|
by: Dave Burns |
last post by:
Hello,
I am trying to specify a logical default value for a in a WCF
Web Service using basicHttpBinding.
I realize that the language defaults are:
int - 0
string - null
bool - false
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |