Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning C4099: type name first seen using 'class' now seen using 'struct' (MS VS 2k8)

Is this warning anything to worry about? I've read that it can cause erratic behaviour?

It's an example I'm trying to compile, could someone explain to me why the author declares the object as a class but then typedef's it to a structure? Is it perfectly normal to do so if the class is POD?

Thanks.

like image 388
Adam Naylor Avatar asked Jan 22 '09 09:01

Adam Naylor


3 Answers

This warning appears when you have a one type declaration that contradicts another (one says "class", the other says "struct"). Given the one definition rule, all declarations except for at most one must be forward declarations. The warning will generally indicate that a forward declaration of a type is wrong and is usually a simple typo and should be fixed. In this case there should be no side effects, but you really should fix it.

There can be, however, some very nasty things happen if you have type name clashes (perhaps caused by using "using namespace" clauses or global namespace pollution). These warnings could be indicating that you are mixing headers from two different libraries and the type names have clashes. Code compiled under these conditions could do some very unexpected things.

My advice - understand why the warning has appeared and fix it. If the warning is in a third party product, insist that they fix it.

like image 177
Daniel Paull Avatar answered Nov 04 '22 01:11

Daniel Paull


Just to bring the comment by MSalters against this post above to the top level. I have had several hard to find linker errors as a result of VC using the 'class' or 'struct' keyword in its mangling of names.

If you don't expect it to be a problem you can be left scratching your head for hours!

like image 41
Richard Corden Avatar answered Nov 04 '22 00:11

Richard Corden


I discuss this warning in depth in my blog posting "Is C4099 really a sillywarning?". My conclusion is that it is best turned off. :-) Well, at least for me.

like image 3
Cheers and hth. - Alf Avatar answered Nov 04 '22 00:11

Cheers and hth. - Alf