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

前端 未结 7 2322
萌比男神i
萌比男神i 2021-01-04 01:42

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

7条回答
  •  暖寄归人
    2021-01-04 01:56

    Richard Corden is correct - there is a reason MS has this warning. For the MS compiler, decorated (mangled) names include which class-key (struct or class) is used to declare a type. If a function that takes some object as an argument or returns that object is referenced somewhere when the wrong class-key is visible, you will not get a compiler error but the linker will complain because the decorated names differ. The linker error only shows the symbol it's looking for, and it's easy to overlook the class-key mismatch there, so the earlier, more detailed compiler warning is valuable. It's still possible that the two versions don't appear in the same compilation unit, of course, and you will probably be scratching your head for a while if you believe that the only difference is default member visibility.

    The difference in mangling conflicts with the C++ standard, which says that forward declarations like struct Foo; and class Foo; are equivalent, and so should use the same mangling.

提交回复
热议问题