help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: uninitializing constructor


From: jinxidoru
Subject: Re: uninitializing constructor
Date: 6 Oct 2006 14:07:01 -0700
User-agent: G2/1.0

I appologize if I am misunderstanding what you are trying to do here.
If so, let me know and I'll try to help better.  It seems that the best
way would be to just not have a default constructor.  As long as you
have other constructors, the default constructor will not be defined.
The default constructor is only implicitly defined if no other
constructors are defined either.

If you really need the default constructor internally, you could make
it private or protected so that it can only be accessed from within the
class.


david wrote:
> Hello,
>
> I'd like to know whether g++ can detect a member variable which is not
> initialized (on purpose) by the constructor.
>
> Easier with a 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;
> }
>
> g++ complains about q beeing used but not initialized, is there a way for it
> to complain about x too ?
> I tried the options -O -Wall -Wextra.
>
> (yes I could put 0 in the constructor, but code size is critical in the
> embedded environment I use, and I'm curious too :-)
>
> I also tried "A () const {}" but it is refused.
>
> I know from comp.lang.c++ that this is not a c++standard request to do so,
> but there are always some interesting stuff in gcc that I don't know :-)
> 
> Thanks for any information,
> 
> david



reply via email to

[Prev in Thread] Current Thread [Next in Thread]