0

Below is the base class Storage1:

template<class Key,class Value>
class Storage1
{
    public:
    Storage1();
    void add(Key key, Value value){};
    void Delete(Key key){}
    pair<Value,bool> get(Key key)
    {
        Value v;
        return {v,false};
    }
    bool isFull(){return false;}
 
};

And here is derived class MapBasedStorage which is inheriting from Storage1:

template<class Key,class Value>
class MapBasedStorage: public Storage1<Key,Value>
{
    private:
    map<Key,Value> storage;
    int capacity;

    public:

    MapBasedStorage(int capacity)
    {
        this->capacity=capacity;
        storage.clear();
    }

    void add(Key key, Value value)
    {
        storage[key]=value;
    }

    void Delete(Key key)
    {
        if(storage.find(key)==storage.end())
        {
            cout<<"Key not present.\n";
            return;
        }
        storage.erase(key);
    }

    pair<Value,bool> get(Key key)
    {
        Value value;
        if(storage.find(key)==storage.end())
        {
            return {value,false};
        }
        else
        {
            value =storage[key];
            return {value,true};
        }
    }

    bool isFull()
    {
        if(storage.size()>=capacity)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
};

Problem - When I am trying to make an object of MapBasedStorage class my compiler is throwing an error saying

" c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\PRANJA~1\AppData\Local\Temp\cclJfWLr.o:testing.cpp:(.text+0xe5): undefined reference to `Storage1<int, int>::Storage1()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\PRANJA~1\AppData\Local\Temp\cclJfWLr.o:testing.cpp:(.text$_ZN15MapBasedStorageIiiEC1Ei[__ZN15MapBasedStorageIiiEC1Ei]+0xf): undefined reference to `Storage1<int, int>::Storage1()' "

I think that there is some problem in my code with the inheritance part. Please help!

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60

0 Answers0