I think that you should be including "A.h" instead of "B.h" because the file B.h has a declaration of the class A and no Definitions :)
Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
f(ex) is an instance method.
B p;
p.f(ex);
and include "A.h" in B.cpp.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Others suggestion is right and should fix the code.:
1. change the "B.h" to A.h while including in the 1st line of B.cpp
2. You are calling f() without an object. Note that f() is a member of B so you need to create an object of B and call f()
Thus, you B.cpp should like:
#include "A.h"
#include <iostream>
using namespace std;
void B::f(A a){
cout << a.x;
}
B::B() {
}
int main(int argc, char argv[]){
A ex;
B b;
b.f(ex);
return 0;
}
Compile like this : g++ -o out B.cpp A.cpp
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140