I need to have a single global variable containing some members. I read
that using a singleton class is not recommended and really I don't have
a need for a class. So I just tested g++ -c on a code fragment:
---------------------------
struct {
int a, b, c ;
} mystruct ;
class {
int a, b, c ;
} myclass ;
---------------------------
g++ -c gives me the warnings:
singleton.cpp:7: warning: non-local variable ‘<anonymous struct>
mystruct’ uses anonymous type
singleton.cpp:13: warning: non-local variable ‘<anonymous class>
myclass’ uses anonymous type
However, testing the struct declaration in C does not give any warnings.
OK, C++ is pickier than C, so this is fine. But I don't really know what
to make of the warnings that g++ gave me. What is the potential problem
if a non-local variable has an anonymous type?
Apparently if a **local** variable has an anonymous type it is OK, since
I did not get this warning when I put the mystruct and myclass
definitions into main(). But I don't get the logic behind:
1) the warning
2) the distinction between local and nonlocal in this case
Please explain.
With thanks as always,
Shriramana Sharma.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html