g++ wrarning hides constructor

H

husainap

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
 
O

Old Wolf

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?)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top