gcc version 4.4.6 compiles code successfully. But gcc version 4.8.1 gives compile error.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
class AbstractHashSet
{
protected :
int size;
float load_factor;
int current_limit;
public :
AbstractHashSet() : size(0), load_factor(0.75), current_limit(0){}
int getSize(void) const { return size; }
bool isEmpty(void) const { return size == 0; }
float getLoadFactor(void) const { return load_factor; }
int getCapacity(void) const { return current_limit; }
static int get_preferred_size(int n);
};
template<class KEY>
struct HashSetBaseElement
{
KEY key;
HashSetBaseElement *next;
HashSetBaseElement(KEY k) : key(k),next(NULL){}
virtual ~HashSetBaseElement(){}
};
template<class KEY>
class HashSetBase : public AbstractHashSet
{
public :
bool contains(KEY key)
{
if (size == 0) return false;
return get_element(key) != NULL;
}
protected :
HashSetBaseElement<KEY> *get_element(KEY key)
{
return NULL;
}
};
template<class KEY>
class HashSet : public HashSetBase<KEY>
{
public :
HashSet(int n = 10)
{
HashSetBase<KEY>::setCapacity(n);
}
bool add(KEY key)
{
HashSetBaseElement<KEY> *e = get_element(key);
if (e) return false;
e = new HashSetBaseElement<KEY>(key);
return true;
}
};
template<class KEY_T, class VALUE_T>
class HashMap : public HashSetBase<KEY_T>
{
protected :
struct Entry : public HashSetBaseElement<KEY_T>
{
VALUE_T value;
Entry(KEY_T key, VALUE_T value) : HashSetBaseElement<KEY_T>(key), value(value){}
};
VALUE_T empty_value;
public:
VALUE_T &get(KEY_T key)
{
Entry *e = (Entry*)get_element(key);
if (e) return e->value;
return empty_value;
}
};
struct Space
{
friend bool operator<(const Space &a, const Space &b)
{ return true; }
friend bool operator>(const Space &a, const Space &b)
{ return true; }
};
int main()
{
HashMap<int,Space*> pos_map;
pos_map.get(100);
cout<<"Hello World";
return 0;
}
Compile error:
Error(s): source_file.cpp: In instantiation of ‘VALUE_T& HashMap::get(KEY_T) [with KEY_T = int; VALUE_T = Space*]’:source_file.cpp:98:20: required from here
source_file.cpp:82:34: error: ‘get_element’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
Entry e = (Entry)get_element(key);
source_file.cpp:82:34: note: declarations in dependent base ->‘HashSetBase’ are not found by unqualified lookup
source_file.cpp:82:34: note: use ‘this->get_element’ instead