Reputation: 159
What I have is :
#include "thread.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
vector<Requester*> requesters; //global
struct Requester {
vector<thread> t;
vector<int> tracks;
};
Then in my function I have:
void serviceQ(){
vector<Requester*> test = requesters; //error
}
The error is:
no suitable user-defined conversion from "std::vector<<error-type> *, std::allocator<<error-type> *>>" to "std::vector<Requester *, std::allocator<Requester *>>" exists
I'm very confused as to why this is. Why does it call my global variable an error type in the function? If I were to do something like:
void serviceQ(){
vector<Requester*> test;
//do some stuff
vector<Requester*> result = test; //no error
}
Then there is no error.
Upvotes: 0
Views: 72
Reputation: 56567
You need to define
vector<Requester*> requesters; //global
after the definition of struct Requester
, as otherwise the compiler doesn't know what Requester*
means when it attempts to define the corresponding vector<Requester*>
. Alternatively, you can just declare
struct Requester;
above the line vector<Requester*> requesters;
.
Upvotes: 3