I'm basically having header issues.
#include "Base.h"
class Factory
{
public:
static Base generateReply(int input);
};
And then the factory cxx file
#include "derived1.h"
#include "Factory.h"
Base Factory::generateReply(int input)
switch(input)
{
case(0):
return Base();
case(1):
return derived1();
.....
}
And then I have the base class header file
class Base
{
protected:
std::string type;
public:
Base(){};
Base(std::string in);
virtual std::string doStuff();
}
Along with it's cxx file
#include "Base.h"
Base::Base(std::string in)
{
type = in;
}
and then the derived one class
#include "Base.h"
class derived1: public Base
{
public:
derived1();
derived1(std::string in) : Base(in){};
std::string doStuff();
}
followed by the cxx file for it
#include "derived1.h"
std::string derived1::doStuff()
{
return type;
}
Now each individual component compiles just fine. It's when I try to link everything together that everything goes all wrong. I get things such as
derived1.cxx:20: undefined reference to `Base::helper1(unsigned char) Where helper1 is a protected method that does exist(in my code) in Base
Or even
derived1.cxx:28: undefined reference to `derived1::helper2(unsigned char, unsigned char) Where helper2 is a private method for derived that does exist in my code. Which is weird since derived1 compiled just fine. You would think it would have thrown an error for finding it's helper2 method during compilation?
Or if I mess around with my includes I will get
error: could not convert ‘SenseType' from ‘SenseType’ to ‘Response’
I know it's my includes that are messed up, or maybe I just am completely incapable of even doing a factory pattern. All the examples online make it look like I did it right, they just never have the includes(s) included. I'm guessing it's
I do have guards for all of my header files. Also, if it's of any help, all of the linker errors are in the derived class.