I am trying to get the program below to work. I keep getting the error below, and I can't figure out why???

Derived.obj : error LNK2001: unresolved external symbol "public: virtual class Other * __thiscall Derived::add(int,int)" (?add@Derived@@UAEPAVOther@@HH@Z)

#ifndef _BASE_H_
#define _BASE_H_

#include "Other.h"

class Base{
public:
    virtual Other *add(int x, int y) = 0;
};
#endif  // !defined _BASE_H_







#ifndef _DERIVED_H_
#define _DERIVED_H_

#include "Base.h"

class Derived : public Base{
public:
    Derived();    
    virtual Other *add(int x, int y);       
};    
#endif







#include "Derived.h"

Derived::Derived()
{       
}

Other *add(int x, int y)
{
    int z = (x + y);
    return new Other (z);
}






#ifndef _OTHER_H_
#define _OTHER_H_    

class Other{
public:
    Other();    
    Other(int val);

private:
    int value;    
};    
#endif








#include "Other.h"   

Other::Other()
{    
}

Other::Other(int val)
{
    value = val;
}







#include <iostream>
#include <string>
#include "Derived.h"
#include "Other.h"    

using namespace std;

int main ()
{
    Derived derived;
//  Other * other;
//  other = (derived.add(4,6));
//  cout << z << endl;
    system("pause");    

  return 0;
}

Edited 3 Years Ago by coolbeanbob

The function you wrote as follows

Other *add(int x, int y)
{
    int z = (x + y);
    return new Other (z);
}

is not part of any class. Should it be part of the Derived class?

Try

Other* Derived::add(int x, int y)
{
    int z = (x + y);
    return new Other (z);
}
This article has been dead for over six months. Start a new discussion instead.