g++ wrarning hides constructor

Discussion in 'C++' started by husainap@gmail.com, Sep 12, 2005.

  1. Guest

    Hi,

    I have code like this

    file1.h
    =======
    typedef struct myStructName{
    ....
    ...
    ...
    }MyStructName;

    file2.h
    =======
    extern int myStructName (MyStructName *myName);


    file3.c
    ======
    #include "file1.h"
    #include "file2.h"
    .......
    .......
    .......


    While compling with g++ I am getting warning like,
    In file included from file3.c:line #:
    file2.h :279: warning: `int myStructName (MyStructName *)' hides
    constructor for `struct myStructName'

    Is there any compile time option to hise this warning? or any other
    solution to hide this warning

    Thankns
    Husain
     
    , Sep 12, 2005
    #1
    1. Advertising

  2. > Is there any compile time option to hise this warning? or any other
    > solution to hide this warning


    Use unique names ?

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Sep 12, 2005
    #2
    1. Advertising

  3. Old Wolf Guest

    Re: g++ wrarning hides constructor

    wrote:
    > Hi,
    >
    > I have code like this
    >
    > typedef struct myStructName{
    > }MyStructName;
    >
    > extern int myStructName (MyStructName *myName);
    >
    > While compling with g++ I am getting warning like,
    > file2.h :279: warning: `int myStructName (MyStructName *)' hides
    > constructor for `struct myStructName'


    In case you didn't understand the error: "myStructName" is
    a type name. Then you declare a function called "myStructName".
    So you have a type and a function with the same name.
    The warning is telling you that you now will not be able to
    construct an object like:

    myStructName s;

    because the function name hides the type name.
    (Of course, you can construct it using its alias "MyStructName",
    or by specifying "struct myStructName").

    > Is there any compile time option to hise this warning? or any
    > other solution to hide this warning


    IMHO the best thing to do is to stop using the same name
    for a function and a type !

    You should declare your struct as:

    struct MyStructName
    {
    };

    The typedef is just a waste of space (why declare 2 type names
    when you only need one?)
     
    Old Wolf, Sep 12, 2005
    #3
    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. Reb
    Replies:
    3
    Views:
    3,192
    Anthony Williams
    Nov 27, 2003
  2. Wayne Brantley

    hides inherited member ApplicationInstance

    Wayne Brantley, Dec 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    6,978
    Steven Cheng[MSFT]
    Dec 19, 2005
  3. Aire
    Replies:
    3
    Views:
    489
    Mike Wahler
    Jan 25, 2004
  4. Tom
    Replies:
    3
    Views:
    512
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,349
Loading...

Share This Page