1

For example:

class Hooks {


 public:
 std::string text;
 std::string hookfont;

 HookFromEncouter()
 {
     text = "Would you befriend an elf? ";
     hookfont = "COPRGTB.ttf";
 }

 HookFromEncouter(string text1, string hookfont1)
 {
     text = text;
     hookfont = hookfont1;
 }

 };

I need to store arrays of this object in a queue:

How do I create and access such a queue with object arrays of variable length? Or static length?

Such as:

queue<Hooks[]> Hooks_queue;

Great. This code gives me an error though:

vector<Hooks> hooks_import;
hooks_import.push_back(Hooks());
hooks_import.push_back(Hooks());

Hooks_queue.push(hooks_import);

Error: No instance of overloaded function

1
  • 5
    queue<vector<Hooks>> ? Commented Jun 17, 2015 at 13:53

1 Answer 1

4

If the internal arrays are meant to be variable length or the length won't be known until run-time you could use

std::queue<std::vector<Hooks>> Hooks_queue;

If the size is fixed and known at compile time, you could use

std::queue<std::array<Hooks, N>> Hooks_queue;

Where N is the size of each array

Sign up to request clarification or add additional context in comments.

4 Comments

Great. This code gives me an error though: vector<Hooks> hooks_import; hooks_import.push_back(Hooks()); hooks_import.push_back(Hooks()); Hooks_queue.push(hooks_import); Error: No instance of overloaded function
Great. This code gives me an error though: 'code' vector<Hooks> hooks_import; hooks_import.push_back(Hooks()); hooks_import.push_back(Hooks()); Hooks_queue.push(hooks_import); 'code' Error: No instance of overloaded function
Yes just did. So how do I fix this? Thank you
std::queue<std::vector<Hooks>> Hooks_queue; As you instructed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.