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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -