Re: Default constructor error

Discussion in 'C++' started by Andrey Tarasevich, May 20, 2011.

  1. On 5/19/2011 10:14 AM, Ruben Safir wrote:
    > I'm getting this warning that appears in the 4.6 GCC compiler that didn't
    > happen before.
    >
    > the warning is
    >
    > /home/ruben/cplus/link_list_template_mysql/stats.h|45 col 42| warning:
    > converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
    >
    > if comes from a default constructor
    >
    > Distribution():freq(NULL), occurances(0){};
    >
    >
    >
    > occurances is an int type, and the compiler is complaining about
    > occurances(0)


    What makes you think that it complains about `occurances` specifically?
    My first guess would be that it is complaining about `freq(NULL)`.

    > it goes away when I change it to
    >
    > Distribution():freq(NULL){
    > occurances = 0;
    > };
    >
    >
    > but then it complains about freq which is of type T in a template


    Well, again, my guess would be that the compiler was complaining about
    `freq(NULL)` all the time. However, due to some quirk in the
    implementation this version of the code does not produce the same
    warning (even though the alleged issue is still there).

    How is `freq` declared?

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, May 20, 2011
    #1
    1. Advertising

  2. Andrey Tarasevich

    vishaltiwari

    Joined:
    May 20, 2011
    Messages:
    3
    can you pls give more details of class Distribution,

    I suspect the issue is not with freq(NULL) , just check the code before the constructor.
    Some times it happen.
    vishaltiwari, May 20, 2011
    #2
    1. Advertising

  3. Andrey Tarasevich

    Ruben Safir Guest

    Andrey Tarasevich <> wrote:
    > On 5/19/2011 10:14 AM, Ruben Safir wrote:
    >> I'm getting this warning that appears in the 4.6 GCC compiler that didn't
    >> happen before.
    >>
    >> the warning is
    >>
    >> /home/ruben/cplus/link_list_template_mysql/stats.h|45 col 42| warning:
    >> converting to non-pointer type ?int? from NULL [-Wconversion-null]
    >>
    >> if comes from a default constructor
    >>
    >> Distribution():freq(NULL), occurances(0){};
    >>
    >>
    >>
    >> occurances is an int type, and the compiler is complaining about
    >> occurances(0)

    >
    > What makes you think that it complains about `occurances` specifically?
    > My first guess would be that it is complaining about `freq(NULL)`.
    >


    Because it says so specifically that the error is at occurances. It
    says error at line# col#

    >> it goes away when I change it to
    >>
    >> Distribution():freq(NULL){
    >> occurances = 0;
    >> };
    >>
    >>
    >> but then it complains about freq which is of type T in a template

    >
    > Well, again, my guess would be that the compiler was complaining about
    > `freq(NULL)` all the time.


    No that analysis is wrong. The error message then changes and says it
    is specifically and freq


    > However, due to some quirk in the
    > implementation this version of the code does not produce the same
    > warning (even though the alleged issue is still there).
    >
    > How is `freq` declared?
    >


    the problem is not freq, as a fact.

    Ruben
    Ruben Safir, May 21, 2011
    #3
  4. On 5/20/2011 7:37 PM, Ruben Safir wrote:
    > Andrey Tarasevich<> wrote:
    >> On 5/19/2011 10:14 AM, Ruben Safir wrote:
    >>> I'm getting this warning that appears in the 4.6 GCC compiler that didn't
    >>> happen before.
    >>>
    >>> the warning is
    >>>
    >>> /home/ruben/cplus/link_list_template_mysql/stats.h|45 col 42| warning:
    >>> converting to non-pointer type ?int? from NULL [-Wconversion-null]
    >>>
    >>> if comes from a default constructor
    >>>
    >>> Distribution():freq(NULL), occurances(0){};
    >>>
    >>>
    >>>
    >>> occurances is an int type, and the compiler is complaining about
    >>> occurances(0)

    >>
    >> What makes you think that it complains about `occurances` specifically?
    >> My first guess would be that it is complaining about `freq(NULL)`.
    >>

    >
    > Because it says so specifically that the error is at occurances. It
    > says error at line# col#
    >
    >>> it goes away when I change it to
    >>>
    >>> Distribution():freq(NULL){
    >>> occurances = 0;
    >>> };
    >>>
    >>>
    >>> but then it complains about freq which is of type T in a template

    >>
    >> Well, again, my guess would be that the compiler was complaining about
    >> `freq(NULL)` all the time.

    >
    > No that analysis is wrong. The error message then changes and says it
    > is specifically and freq
    >
    >
    >> However, due to some quirk in the
    >> implementation this version of the code does not produce the same
    >> warning (even though the alleged issue is still there).
    >>
    >> How is `freq` declared?
    >>

    >
    > the problem is not freq, as a fact.


    Or so you claim. Post the minimal _complete_ code that reproduces the
    error.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, May 21, 2011
    #4
  5. Andrey Tarasevich

    Drew Lawson Guest

    In article <ir6u09$or$>
    Ruben Safir <> writes:
    >Andrey Tarasevich <> wrote:
    >> On 5/19/2011 10:14 AM, Ruben Safir wrote:
    >>> I'm getting this warning that appears in the 4.6 GCC compiler that didn't
    >>> happen before.
    >>>
    >>> the warning is
    >>>
    >>> /home/ruben/cplus/link_list_template_mysql/stats.h|45 col 42| warning:
    >>> converting to non-pointer type ?int? from NULL [-Wconversion-null]
    >>>
    >>> if comes from a default constructor
    >>>
    >>> Distribution():freq(NULL), occurances(0){};
    >>>
    >>>
    >>>
    >>> occurances is an int type, and the compiler is complaining about
    >>> occurances(0)

    >>
    >> What makes you think that it complains about `occurances` specifically?
    >> My first guess would be that it is complaining about `freq(NULL)`.
    >>

    >
    >Because it says so specifically that the error is at occurances. It
    >says error at line# col#


    That is where the compiler was looking when it determined that
    something was wrong. Ideally, that is where the problem is, but
    frequently it isn't. If the compiler tells me I have a problem on
    line 25, I usually look at line 24.

    Seeing as the error explicitly says "NULL," I'd look at the part
    of the code that has "NULL."

    --
    Drew Lawson | What is an "Oprah"?
    | -- Teal'c
    |
    Drew Lawson, May 23, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aire
    Replies:
    3
    Views:
    450
    Mike Wahler
    Jan 25, 2004
  2. Replies:
    9
    Views:
    938
    Alf P. Steinbach
    Mar 6, 2006
  3. Replies:
    4
    Views:
    400
    Salt_Peter
    Oct 12, 2006
  4. desktop
    Replies:
    2
    Views:
    440
    Victor Bazarov
    Jun 6, 2007
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,184
Loading...

Share This Page