I'm looking to create a priority_queue with the vector created in main() using B::weight to order the queue. How might I go about doing that?
Code:
#include <vector>
#include <string>
template <typename T>
class A
{
public:
class B
{
private:
B()
{
weight = 0;
}
T data;
int weight;
friend class A;
public:
int get_weight()
{
return weight;
}
bool operator==(const B& rhs) const
{
return (*this).weight == rhs.weight;
}
bool operator<(const B& rhs) const
{
return (*this).weight < rhs.weight;
}
bool operator>(const B& rhs) const
{
return (*this).weight > rhs.weight;
}
};
A() {}
virtual ~A() {}
B* create_B(T data, int weight = 0);
};
template <typename T>
typename A<T>::B* A<T>::create_B(T data, int weight = 0)
{
B* new_B = new B;
new_B->data = data;
new_B->weight = weight;
return new_B;
}
int main()
{
A<std::string> myA;
std::vector<A<std::string>::B*> stuff;
stuff.push_back(myA.create_B("string1", 1));
stuff.push_back(myA.create_B("string2", 2));
return 0;
}