I have following five files. After successfully compiling them I receive linking errors. Please note: I don't want to use inheritance here.
one.cpp
#include"one.hpp"
#include"two.hpp"
void one::method()
{
ptrTwoObj = new two;
ptrTwoObj->method();
}
one.hpp
class one{
public:
void method();
};
two.cpp
#include<iostream>
#include"two.hpp"
void two::method()
{
std::cout<<"In class two"<<std::endl;
}
two.hpp
class two{
public:
void method();
};
extern two *ptrTwoObj;
main.cpp
#include<iostream>
#include"bsap.hpp"
int main()
{
one *ptrOneObj = new one;
ptrOneObj->method();
}
I compiled above files with following command
`g++ one.cpp two.cpp main.cpp`
And following are the linking errors
`/tmp/ccwE53uC.o: In function `one::method()':
one.cpp:(.text+0x19): undefined reference to `ptrTwoObj'
one.cpp:(.text+0x20): undefined reference to `ptrTwoObj'
collect2: error: ld returned 1 exit status`