D
david
Hello,
I'd like to know whether the compiler can detect a member variable which is
not initialized (on purpose) by the constructor.
Easier with an simple example (the class is supposed to be a fixed point
variable):
class A
{
private:
int my_value;
A (int init) { my_value = init; }
public:
A () {}
A (const A& init) { my_value = init.my_value; }
A& operator = (int scalar) { my_value = scalar << 8; }
...
};
int main (void)
{
int p, q;
A x, y;
p = q;
y = x;
}
The compiler complains about q beeing used but not initialized,
is there a way for it to complain about x too ?
(yes I could put 0 in the constructor, but code size is critical in the
embedded environment I use, and I'm curious too
If of any interest for the answer, I'm using gnu-g++. Before I post to the
gnu newsgroup, I'd like to know if the answer is part of some c++ standards.
(I also tried "A () const {}" but it is refused)
Thanks for any information,
david
I'd like to know whether the compiler can detect a member variable which is
not initialized (on purpose) by the constructor.
Easier with an simple example (the class is supposed to be a fixed point
variable):
class A
{
private:
int my_value;
A (int init) { my_value = init; }
public:
A () {}
A (const A& init) { my_value = init.my_value; }
A& operator = (int scalar) { my_value = scalar << 8; }
...
};
int main (void)
{
int p, q;
A x, y;
p = q;
y = x;
}
The compiler complains about q beeing used but not initialized,
is there a way for it to complain about x too ?
(yes I could put 0 in the constructor, but code size is critical in the
embedded environment I use, and I'm curious too
If of any interest for the answer, I'm using gnu-g++. Before I post to the
gnu newsgroup, I'd like to know if the answer is part of some c++ standards.
(I also tried "A () const {}" but it is refused)
Thanks for any information,
david