vector that holds nested class

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?

I compiled this with no errors:
1
2
3
4
5
6
7
8
9
10
11
12
#include <vector>

class A {
	class B {
	};

public:
	std::vector<B> vec;
};

int main() {
}

You probably need to post more code.
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
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...
I removed the template<class M> from the top, still getting the same error. What specifically needs to be done?
Did you change all "M" to "T"? I don't think you should be getting the exact same errors.
Topic archived. No new replies allowed.