c++ - Multiple definitions in different translation units -


i know 1 definition rule can define class in multiple translation units if have same tokens in same order, program weird me

file main.cpp

#include "source.h"  struct mystructure {     int field1;     float field2; };  int main() {      mystructure myvar;     myvar.field2= 2.0f;      mycustomfunction(myvar);      return 0; } 

file source.h

struct mystructure;  void mycustomfunction(mystructure& vv); 

file source.cpp

#include "source.h"  struct mystructure {     char otherfield;     int anotherone;     bool anotheranotherone; };  void mycustomfunction(mystructure& vv) {     vv.otherfield = 'a'; } 

i'm using msvc2012 , compiler isn't complaining. why that? normal?

it's hard compiler complain, since never sees conflicting declarations during same compilation. code not correct, unfortunately compilers don't pick every mistake, nor standard require them to.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -