If I inject a dependency, let it be instance of class A, in a class B, which is defined in a shared library, will the shared library need the object files of class A for linkage? (Meant is the g++ linkage stage after the compilation of the library, not the OS linkage at runtime)
Actually I tried this on linux and it does not. Is this true for all platforms? (Ignore symbol visibility in this case, unless essential)
a.h
#ifndef SOME_HEADERA_H
#define SOME_HEADERA_H
struct A{
void whoop();
};
#endif
a.cpp
#include <iostream>
#include "a.h"
void A::whoop (){
std::cout << "A whooped."<< std::endl;
}
b.h
#ifndef SOME_HEADERB_H
#define SOME_HEADERB_H
class A;
struct B {
void whoopUsingA(A* a);
};
#endif
b.cpp
#include "b.h"
#include "a.h"
#include <iostream>
void B::whoopUsingA (A* a){
std::cout << "B whoops A."<< std::endl;
a->whoop();
}
main.cpp
#include "a.h"
#include "b.h"
int main (int argc, const char* argv[]) {
A a;
B b;
b.whoopUsingA(&a);
return 0;
}