473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class variables: scoping

Hello,

Suppose I have some method:

Foo::foo() {
static int x;
int y;
/* ... */
}

Here variables x is shared by all instances of the class, but has
function scope. On the other hand, variable y, also has function
scope, but is reinitialized each time the method is called.

Now, I would like to have a variable which has function scope,
that is, is not visible by other class functions. However, every
time I instantiate an instance of Foo a new such variable is created.
Essentially, I would like to have something like the equivalent of:

class Foo {
/* ... */
private:
/* ... */
int z;
/* ... */
};

However, I do not want to have all methods inside Foo see z. I only
want method foo to see it, just like I did for x which can only be
seen by foo().

The value of z should survive different calls from within the same
instance, but should be initialized for each new instance, like above.
But it should have method scope, not class scope.

It would be nice if C++ were extended to include this nice idea.
It could for example allow something like:

Foo::foo() {
static int x;
int y;
semistatic z;
/* ... */
}

Where semistatic means: shared by all invocations within the same
instance, and only visible within foo().

I think this feature is missing from C++ and is quite useful. Because
if some class variable is used only in one method, then why should I
have to place it in the class definition. It's like having to make
things global just because they are shared by instances.
Comments welcome.

Regards,

Neil
Jul 22 '05
30 2275
"Neil Zanella" <nz******@cs.mu n.ca> wrote in message
I don't understand exactly how usnig functors could
help in this situation. However I have come up with
I think I misunderstood your original requirement. Thought you wanted to
make a private variable which is accessible to only 1 member function.
#include <iostream>
#include <cstdlib>
#include <map>

class Foo {
public:
int foo1() {
static std::map<Foo *, bool> computed;
if (!computed[this]) {
std::cout << "Computing foo1..." << std::endl;
x1 = compute(0, 0);
computed[this] = true;
} else
std::cout << "Reusing computed foo1 result..." << std::endl;
return x1;
}
int foo2() {
static std::map<Foo *, bool> computed;
if (!computed[this]) {
std::cout << "Computing foo2..." << std::endl;
x2 = compute(0, 1);
computed[this] = true;
} else
std::cout << "Reusing computed foo2 result..." << std::endl;
return x2;
}
int foo3() {
static std::map<Foo *, bool> computed;
if (!computed[this]) {
std::cout << "Computing foo3..." << std::endl;
x3 = compute(1, 0);
computed[this] = true;
} else
std::cout << "Reusing computed foo3 result..." << std::endl;
return x3;
}
int foo4() {
static std::map<Foo *, bool> computed;
if (!computed[this]) {
std::cout << "Computing foo4..." << std::endl;
x4 = compute(1, 1);
computed[this] = true;
} else
std::cout << "Reusing computed foo4 result..." << std::endl;
return x4;
}
private:
int compute(int a, int b) {
/* suppose this takes a long time to run */
return rand() + 2 * a + b; /* for simplicity */
}
int x1, x2, x3, x4; /* data to be computed */
};
Why not just

class Foo {
public:
Foo() : x1(), x1_computed(fal se) { }
private:
int x1;
bool x1_computed;

If you want to get fancy, you can try the recursive derivation idea I posted
in "set/get in c++".

int main() {

/* run program without waiting for unnecessary computations */
/* available which would unnecessarily initialize class data */

std::cout << "Foo 1 Instance:" << std::endl;

Foo foo1;
std::cout << foo1.foo1() << std::endl;
std::cout << foo1.foo1() << std::endl;
std::cout << foo1.foo2() << std::endl;

/* foo1.foo3(), and foo1.foo4() never called */
/* hence OO program can run as fast as a procedural program */

std::cout << "Foo 2 Instance: " << std::endl;

Foo foo2;
std::cout << foo2.foo2() << std::endl;
std::cout << foo2.foo3() << std::endl;
std::cout << foo2.foo4() << std::endl;
std::cout << foo2.foo4() << std::endl;

/* foo1.foo1() never called */
/* hence OO program can run as fast as a procedural program */

}


Jul 22 '05 #21
On 4 Apr 2004 13:24:10 -0700, nz******@cs.mun .ca (Neil Zanella) wrote:
Leor Zolman <le**@bdsoft.co m> wrote in message:
>Foo::foo() {
> static int x;
> int y;
> /* ... */
>}
>
>Here variable x is shared by all instances of the class,
Not /that/ variable x, if you're referring to the one in Foo:foo(). That's
a block-scope static, which means it can only be referred to within that
function (and its value persists across multiple calls to it. By the way,
it gets initialized to zero the first time the function is called, if you
don't give it an initializer.)


Perhaps my explanation was somewhat inadequate. What you have stated in the
above paragraph is correct. Indeed, x can only be referred to from within
member function Foo::foo(). And indeed since it is static the compiler will
automaticall y arrange for it to be initialized to zero when no initializer
is present. What I meant to express by saying that x is shared by all
instances of Foo is exemplified in the following code:

[code snipped]

I think you're confusing yourself by saying that the x above is "shared by
all instances of Foo" because in fact it is shared by all instances of
/everything/, along with all /non-instances/ of everything (non-member
functions), that end up calling Foo::foo(). x behaves just like a
file-scope ("global") variable...that just happens to only be visible
within Foo::foo().

without changing the contents of main and without changing the contents
of the class definition (which seems impossible in C++, since it does not
support the feature I describe).
>The value of z should survive different calls from within the same
>instance, but should be initialized for each new instance, like above.
>But it should have method scope, not class scope.
I /think/ I see what you want, but there's no primitive way to declare that
in C++: You want an instance variable (one copy associated with each
instance of an object) that is only in scope within a particular function,


Correct. That is indeed the feature I was describing. Furthermore I was
poining out that C++ supports combinations:

(one copy per class, class scope) (static data members in class body)
(one copy per class, function scope) (static data members in function body)
(one copy per instance, class scope) (automatic data in class body)

but not the combination:

(one copy per instance, function scope)


Perhaps it is because Bjarne and everyone else involved in the evolution of
C++ didn't think that last permutation was useful enough, if in fact it
ever occurred to them. I don't know, but the idea sure never occurred to
/me/.

>I think this feature is missing from C++ and is quite useful. Because
>if some class variable is used only in one method, then why should I
>have to place it in the class definition.


To indicate to the compiler that it has to make room for it in each object
instantiated. At least the way C++ is currently defined ;-)


Hmmm... but the compiler went and fetched those static variables for
the BSS segment. I gues they belong to another data segment altogether
hence that is what makes it possible???


What's a BSS segment? I'm sorry, I swore off assembly language and as much
as possible pertaining to it a long time ago. But if you understood what I
said above what it means for a variable to be static to a function, I think
you'll probably have the answer to your question.

Cheers,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #22
On 4 Apr 2004 13:24:10 -0700, nz******@cs.mun .ca (Neil Zanella) wrote:
Leor Zolman <le**@bdsoft.co m> wrote in message:
>Foo::foo() {
> static int x;
> int y;
> /* ... */
>}
>
>Here variable x is shared by all instances of the class,
Not /that/ variable x, if you're referring to the one in Foo:foo(). That's
a block-scope static, which means it can only be referred to within that
function (and its value persists across multiple calls to it. By the way,
it gets initialized to zero the first time the function is called, if you
don't give it an initializer.)


Perhaps my explanation was somewhat inadequate. What you have stated in the
above paragraph is correct. Indeed, x can only be referred to from within
member function Foo::foo(). And indeed since it is static the compiler will
automaticall y arrange for it to be initialized to zero when no initializer
is present. What I meant to express by saying that x is shared by all
instances of Foo is exemplified in the following code:

[code snipped]

I think you're confusing yourself by saying that the x above is "shared by
all instances of Foo" because in fact it is shared by all instances of
/everything/, along with all /non-instances/ of everything (non-member
functions), that end up calling Foo::foo(). x behaves just like a
file-scope ("global") variable...that just happens to only be visible
within Foo::foo().

without changing the contents of main and without changing the contents
of the class definition (which seems impossible in C++, since it does not
support the feature I describe).
>The value of z should survive different calls from within the same
>instance, but should be initialized for each new instance, like above.
>But it should have method scope, not class scope.
I /think/ I see what you want, but there's no primitive way to declare that
in C++: You want an instance variable (one copy associated with each
instance of an object) that is only in scope within a particular function,


Correct. That is indeed the feature I was describing. Furthermore I was
poining out that C++ supports combinations:

(one copy per class, class scope) (static data members in class body)
(one copy per class, function scope) (static data members in function body)
(one copy per instance, class scope) (automatic data in class body)

but not the combination:

(one copy per instance, function scope)


Perhaps it is because Bjarne and everyone else involved in the evolution of
C++ didn't think that last permutation was useful enough, if in fact it
ever occurred to them. I don't know, but the idea sure never occurred to
/me/.

>I think this feature is missing from C++ and is quite useful. Because
>if some class variable is used only in one method, then why should I
>have to place it in the class definition.


To indicate to the compiler that it has to make room for it in each object
instantiated. At least the way C++ is currently defined ;-)


Hmmm... but the compiler went and fetched those static variables for
the BSS segment. I gues they belong to another data segment altogether
hence that is what makes it possible???


What's a BSS segment? I'm sorry, I swore off assembly language and as much
as possible pertaining to it a long time ago. But if you understood what I
said above what it means for a variable to be static to a function, I think
you'll probably have the answer to your question.

Cheers,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #23
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message
Why not just

class Foo {
public:
Foo() : x1(), x1_computed(fal se) { }
private:
int x1;
bool x1_computed;
What if a single function computes 10 data members. Wouldn't you then
rather associate one boolean variable with the function than have one
for each data member? I am not just considering setters and getters.
There are more complicated functions that manipulate multiple data
members in more complicated classes. On the other hand I would
probably have a boolean variable for each private data member
if it were the case that the functions did not operate on
disjoint data members.

Anyhow, to answer your question, I don't like having all those booleans
and what not linger inside class Foo when they are method specific, which
is what I originally posted about. In any case perhaps something like

template<class t>
struct Data {
T value;
bool computed;
};

could perhaps help reduce the clutter... (yes? no?).
If you want to get fancy, you can try the recursive derivation idea I posted
in "set/get in c++".


I would like to comment on the "set/get in C++" thread. The idea described
therein is not a new idea. Some C++ toolkits such as Qt implement it already.
For instance see the Q_PROPERTY Qt macro. This takes the following format:

Q_PROPERTY( Priority priority READ priority WRITE setPriority )

You may want to read about it in with the assistant Qt application.

However, if classes were all about setters and getters that returned and
set a single state variable each then OOAD would be quite uninteresting.
Nevertheless for some applictions several short setters and getters may
be all it takes to describe some of the more trivial classes. In general
however we can have more complicated setter implementations , perhaps even
so for the getters, and the internal representation of the data could be
quite different from what appears to be presented by the class interface.

Thanks,

Neil
Jul 22 '05 #24
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message
Why not just

class Foo {
public:
Foo() : x1(), x1_computed(fal se) { }
private:
int x1;
bool x1_computed;
What if a single function computes 10 data members. Wouldn't you then
rather associate one boolean variable with the function than have one
for each data member? I am not just considering setters and getters.
There are more complicated functions that manipulate multiple data
members in more complicated classes. On the other hand I would
probably have a boolean variable for each private data member
if it were the case that the functions did not operate on
disjoint data members.

Anyhow, to answer your question, I don't like having all those booleans
and what not linger inside class Foo when they are method specific, which
is what I originally posted about. In any case perhaps something like

template<class t>
struct Data {
T value;
bool computed;
};

could perhaps help reduce the clutter... (yes? no?).
If you want to get fancy, you can try the recursive derivation idea I posted
in "set/get in c++".


I would like to comment on the "set/get in C++" thread. The idea described
therein is not a new idea. Some C++ toolkits such as Qt implement it already.
For instance see the Q_PROPERTY Qt macro. This takes the following format:

Q_PROPERTY( Priority priority READ priority WRITE setPriority )

You may want to read about it in with the assistant Qt application.

However, if classes were all about setters and getters that returned and
set a single state variable each then OOAD would be quite uninteresting.
Nevertheless for some applictions several short setters and getters may
be all it takes to describe some of the more trivial classes. In general
however we can have more complicated setter implementations , perhaps even
so for the getters, and the internal representation of the data could be
quite different from what appears to be presented by the class interface.

Thanks,

Neil
Jul 22 '05 #25
"Neil Zanella" <nz******@cs.mu n.ca> wrote in message
news:b6******** *************** **@posting.goog le.com...
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message
Why not just

class Foo {
public:
Foo() : x1(), x1_computed(fal se) { }
private:
int x1;
bool x1_computed;


What if a single function computes 10 data members. Wouldn't you then
rather associate one boolean variable with the function than have one
for each data member? I am not just considering setters and getters.
There are more complicated functions that manipulate multiple data
members in more complicated classes. On the other hand I would
probably have a boolean variable for each private data member
if it were the case that the functions did not operate on
disjoint data members.


OK, I understand your question now -- you don't want to clutter the header
file. Initially I thought you wanted to member variable accessible to only
one function (a kind of super-private access mechanism but also an
indication that your class is too big), then I thought you just wanted to
indicate whether a variable was constructed.
Anyhow, to answer your question, I don't like having all those booleans
and what not linger inside class Foo when they are method specific, which
is what I originally posted about. In any case perhaps something like

template<class t>
struct Data {
T value;
bool computed;
};

could perhaps help reduce the clutter... (yes? no?).
It reduces the number of lines in your code, but the clutter is still there
(namely all the boolean variables) once the template code is expanded.
Besides as you point out, if you want one boolean variable for ten data
members which foo() calculates, the Data<T> is overkill as it constructs 10
booleans. I don't have a perfect or good solution, but maybe you could use
a member variable like,

/*mutable*/ std::set<std::s tring> d_constructed;

and in your functions use the __FUNCTION__ macro to indicate that the
variables of this function are constructed. Note that __FUNCTION__ is not
standard, though there are variations you can try.

void Foo::foo() const {
if (d_constructed. find(__FUNCTION __) == d_constructed.e nd()) {
d_constructed.i nsert(__FUNCTIO N__);
d_x = 3;
d_y = 8;
}
}

The static variables idea in your previous post works could easily cause
trouble in multi-threaded environments.
If you want to get fancy, you can try the recursive derivation idea I posted in "set/get in c++".


I would like to comment on the "set/get in C++" thread. The idea described
therein is not a new idea. Some C++ toolkits such as Qt implement it

already. For instance see the Q_PROPERTY Qt macro. This takes the following format:

Q_PROPERTY( Priority priority READ priority WRITE setPriority )

You may want to read about it in with the assistant Qt application.

However, if classes were all about setters and getters that returned and
set a single state variable each then OOAD would be quite uninteresting.
Nevertheless for some applictions several short setters and getters may
be all it takes to describe some of the more trivial classes. In general
however we can have more complicated setter implementations , perhaps even
so for the getters, and the internal representation of the data could be
quite different from what appears to be presented by the class interface.


Right, the idea is best when the function bodies are more complicated.
Though I did not claim the idea was new, and I first learned about it in
Stroustrup's book.
Jul 22 '05 #26
"Neil Zanella" <nz******@cs.mu n.ca> wrote in message
news:b6******** *************** **@posting.goog le.com...
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message
Why not just

class Foo {
public:
Foo() : x1(), x1_computed(fal se) { }
private:
int x1;
bool x1_computed;


What if a single function computes 10 data members. Wouldn't you then
rather associate one boolean variable with the function than have one
for each data member? I am not just considering setters and getters.
There are more complicated functions that manipulate multiple data
members in more complicated classes. On the other hand I would
probably have a boolean variable for each private data member
if it were the case that the functions did not operate on
disjoint data members.


OK, I understand your question now -- you don't want to clutter the header
file. Initially I thought you wanted to member variable accessible to only
one function (a kind of super-private access mechanism but also an
indication that your class is too big), then I thought you just wanted to
indicate whether a variable was constructed.
Anyhow, to answer your question, I don't like having all those booleans
and what not linger inside class Foo when they are method specific, which
is what I originally posted about. In any case perhaps something like

template<class t>
struct Data {
T value;
bool computed;
};

could perhaps help reduce the clutter... (yes? no?).
It reduces the number of lines in your code, but the clutter is still there
(namely all the boolean variables) once the template code is expanded.
Besides as you point out, if you want one boolean variable for ten data
members which foo() calculates, the Data<T> is overkill as it constructs 10
booleans. I don't have a perfect or good solution, but maybe you could use
a member variable like,

/*mutable*/ std::set<std::s tring> d_constructed;

and in your functions use the __FUNCTION__ macro to indicate that the
variables of this function are constructed. Note that __FUNCTION__ is not
standard, though there are variations you can try.

void Foo::foo() const {
if (d_constructed. find(__FUNCTION __) == d_constructed.e nd()) {
d_constructed.i nsert(__FUNCTIO N__);
d_x = 3;
d_y = 8;
}
}

The static variables idea in your previous post works could easily cause
trouble in multi-threaded environments.
If you want to get fancy, you can try the recursive derivation idea I posted in "set/get in c++".


I would like to comment on the "set/get in C++" thread. The idea described
therein is not a new idea. Some C++ toolkits such as Qt implement it

already. For instance see the Q_PROPERTY Qt macro. This takes the following format:

Q_PROPERTY( Priority priority READ priority WRITE setPriority )

You may want to read about it in with the assistant Qt application.

However, if classes were all about setters and getters that returned and
set a single state variable each then OOAD would be quite uninteresting.
Nevertheless for some applictions several short setters and getters may
be all it takes to describe some of the more trivial classes. In general
however we can have more complicated setter implementations , perhaps even
so for the getters, and the internal representation of the data could be
quite different from what appears to be presented by the class interface.


Right, the idea is best when the function bodies are more complicated.
Though I did not claim the idea was new, and I first learned about it in
Stroustrup's book.
Jul 22 '05 #27
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message news:<7Orcc.259 11
I don't have a perfect or good solution, but maybe you could use
a member variable like,

/*mutable*/ std::set<std::s tring> d_constructed;

and in your functions use the __FUNCTION__ macro to indicate that the
variables of this function are constructed. Note that __FUNCTION__ is not
standard, though there are variations you can try.

void Foo::foo() const {
if (d_constructed. find(__FUNCTION __) == d_constructed.e nd()) {
d_constructed.i nsert(__FUNCTIO N__);
d_x = 3;
d_y = 8;
}
}
Is the __FUNCTION__ macro specific to the gcc compiler suite or does it work
with other compilers as well. In any case standard behavior could be attained
by using an enumeration with something similar to function names in it.
The static variables idea in your previous post works could easily cause
trouble in multi-threaded environments.


Perhaps you are referring to the fact that in a multithreaded applications
two objects may have the same virtual address, hence it is not possible to
identify an object on the basis of its virtual address and be certain that
the application will work. Is this what you are referring to when you mention
that problems may arise in multithreaded applications.

Regards,

Neil
Jul 22 '05 #28
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message news:<7Orcc.259 11
I don't have a perfect or good solution, but maybe you could use
a member variable like,

/*mutable*/ std::set<std::s tring> d_constructed;

and in your functions use the __FUNCTION__ macro to indicate that the
variables of this function are constructed. Note that __FUNCTION__ is not
standard, though there are variations you can try.

void Foo::foo() const {
if (d_constructed. find(__FUNCTION __) == d_constructed.e nd()) {
d_constructed.i nsert(__FUNCTIO N__);
d_x = 3;
d_y = 8;
}
}
Is the __FUNCTION__ macro specific to the gcc compiler suite or does it work
with other compilers as well. In any case standard behavior could be attained
by using an enumeration with something similar to function names in it.
The static variables idea in your previous post works could easily cause
trouble in multi-threaded environments.


Perhaps you are referring to the fact that in a multithreaded applications
two objects may have the same virtual address, hence it is not possible to
identify an object on the basis of its virtual address and be certain that
the application will work. Is this what you are referring to when you mention
that problems may arise in multithreaded applications.

Regards,

Neil
Jul 22 '05 #29
"Neil Zanella" <nz******@cs.mu n.ca> wrote in message
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message news:<7Orcc.259 11
/*mutable*/ std::set<std::s tring> d_constructed;

and in your functions use the __FUNCTION__ macro to indicate that the
variables of this function are constructed. Note that __FUNCTION__ is not standard, though there are variations you can try. Is the __FUNCTION__ macro specific to the gcc compiler suite or does it work with other compilers as well. In any case standard behavior could be attained by using an enumeration with something similar to function names in it.
Borland 6 does not support __FUNCTION__. I think Microsoft does, but ask on
a Microsoft group to be sure, or try it on the compiler.

Instead of maintaining an enum, I was thinking of converting the address of
a function to a string, like this,

void * ptr = static_cast<voi d *>(&X::function );
std::cout << ptr;

But you can't convert a pointer to member function into a void*, even
through reinterpret_cas t, because they usually have different sizes. And
typeid(&X::func tion).name() prints the type of the function, so if
X::function1 and X::function2 have the same signature, typeid.name() prints
the same thing.

To avoid cluttering the header file, why not just use the pointer to
implementation idea where you declare the struct in the cpp file? You get
insulation for free, can use reference counted smart pointers if so desired
(though they have multi-threading problems/challenges too), etc.

The static variables idea in your previous post works could easily cause
trouble in multi-threaded environments.


Perhaps you are referring to the fact that in a multithreaded applications
two objects may have the same virtual address, hence it is not possible to
identify an object on the basis of its virtual address and be certain that
the application will work. Is this what you are referring to when you

mention that problems may arise in multithreaded applications.


It's the standard one. Two threads call your function X::f(). Both see
that the static variable is not constructed. Then both go ahead and
construct it.

The solution is when one thread sees it is not constructed it blocks the
function memory so the other thread cannot do anything, the the first thread
constructs the object and releases the block, and the other thread then sees
the static variable is constructed. There is no native support for this in
C++. You have to use OS functions like critical section and mutexes. Even
if it works, the use of these OS functions is quite expensive. I'm not an
expert on multi-threading (still learning it myself), but those are the
basics.
Jul 22 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
428
by: Neil Zanella | last post by:
Hello, Suppose I have some method: Foo::foo() { static int x; int y; /* ... */ }
166
8673
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
7
2116
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9 ----------------------------------------------------------------------------- This is a consortium of ideas from another thread on topic ----------------------------------------------------------------------------- One of the big issues of organizing items within a class, is there are many...
0
9595
marktang
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...
0
9432
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,...
0
10232
Oralloy
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...
1
10008
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,...
0
9873
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7420
isladogs
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...
0
6682
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();...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.