Mar 5, 2012 at 9:09pm UTC
Trying to define a vector that holds an inner class.
class A
{
private:
class B
{
...
};
public:
vector<B> v;
};
And the compiler gives me the error:
A.h:56: error: ‘B’ was not declared in this scope
A.h:56: error: template argument 1 is invalid
A.h:56: error: template argument 2 is invalid
How to fix?
Mar 5, 2012 at 9:35pm UTC
My entire .h file:
#ifndef _PRIORITYQUEUE_H_
#define _PRIORITYQUEUE_H_
#include <vector>
#include <map>
using namespace std;
template<class T>
class PriorityQueue
{
private:
void percolateUp(int index);
void percolateDown(int index);
template<class M>
class HNode
{
private:
M object;
float priority;
public:
inline M getObject()
{
return this->object;
}
inline float getPriority()
{
return this->priority;
}
inline void setObject(M object)
{
this->object = object;
}
inline void setPriority(float priority)
{
this->priority = priority;
}
};
public:
PriorityQueue();
~PriorityQueue();
void insert(T obj, float priority);
T front();
T pop();
bool isEmpty();
void changePriority(T obj, float new_priority);
void remove(T obj);
vector <Hnode> heap; // errors here
map<T, int*> finder;
};
#endif
Mar 5, 2012 at 9:38pm UTC
You declare Hnode to take a template parameter. You must supply that template parameter. Though I must wonder why Hnode needs its own template parameter M if you only use T with it anyway...
Mar 5, 2012 at 9:41pm UTC
I removed the template<class M> from the top, still getting the same error. What specifically needs to be done?
Mar 5, 2012 at 9:54pm UTC
Did you change all "M" to "T"? I don't think you should be getting the exact same errors.