P
Phil Endecott
Dear Experts,
Say I have this:
struct scoped_foo {
scoped_foo(int n) { enable_foo(n); }
~scoped_foo() { disable_foo(); }
};
and I use it like this:
{
scoped_foo(3);
blah(); // foo is enabled here
}
// foo is disabled here
....except that doesn't work, because I should have written
{
scoped_foo ANY_NAME_HERE(3);
....
I've now made this mistake a few times, and it's annoying.
So, my question: is there anything that I can do in my declaration of
scoped_foo so that trying to use it in this wrong way, i.e. to create
a temporary rather than an object with scope up to the next }, will
give an error, or at least a warning (with g++)?
Thanks for any suggestions!
Phil.
Say I have this:
struct scoped_foo {
scoped_foo(int n) { enable_foo(n); }
~scoped_foo() { disable_foo(); }
};
and I use it like this:
{
scoped_foo(3);
blah(); // foo is enabled here
}
// foo is disabled here
....except that doesn't work, because I should have written
{
scoped_foo ANY_NAME_HERE(3);
....
I've now made this mistake a few times, and it's annoying.
So, my question: is there anything that I can do in my declaration of
scoped_foo so that trying to use it in this wrong way, i.e. to create
a temporary rather than an object with scope up to the next }, will
give an error, or at least a warning (with g++)?
Thanks for any suggestions!
Phil.