AbstractionAnon maybe you're looking my old code I changed the code and have uploaded in
my post:
http://www.cplusplus.com/forum/general/139173/2/#msg737680
at: Jul 30, 2014 at 3:48am
and line 17 in truck.h in this new code is:
and I believe in this line I'm passing car by reference using "&" operator
and line 17 in car.h in this new code is:
and in this line I haven't passed anything at all
I included .cpp in .h file because I thought how would compiler know where is the implementation code but again I guess by doing this I'm kicking the purpose of keeping declaration and implementation separate, BUT When I tried something like this
1. I excluded the #include car.cpp from car.h file and excluded #include truck.cpp from truck.h file
2. changed car.h now it starts like this
#ifndef car_h
#define car_h
class truck;
class car{
rest of the code is same (except I deleted #include car.cpp) as my new code post (only included a forward declaration of truck class)
|
3. changed car.cpp now it starts like this
#include "truck.h"
#include "car.h"
car::car(){
rest of the code is same (just included both truck.h and car.h)
|
4. changed truck.h now it start like this
#ifndef truck_h
#define truck_h
class car;
class truck{
rest of the code is same (except deleted #include truck.cpp)
|
#include "car.h"
#include "truck.h"
truck::truck(){
rest of the code is same
|
and this time compiler gives a weird error
just a few lines like this:
C:\Users\Dani\AppData\Local\Temp\cctVxOGS.o cartruck.cpp:(.text+0x52): undefined reference to `car::car()' {doesn't even mention a line no}
2nd last line is this:
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe C:\Users\Dani\AppData\Local\Temp\cctVxOGS.o: bad reloc address 0x1 in section `.text$_ZN3carD1Ev[_ZN3carD1Ev]'
and last line is:
E:\Education\cpp\temp\cartruck\collect2.exe [Error] ld returned 1 exit status