I have a vector containing pointers to several classes. The classes are defined as so:
class trackerSocket{
public:
~trackerSocket();
int trackerInitialize(string address);
int trackerSend(string getParams);
int trackerRecv();
be_node *responseDict;
bool working;
unsigned int interval;
string trackerid;
unsigned int complete;
unsigned int incomplete;
be_dict *peersDict;
string peersBinary;
bool dictionary;
private:
string address;
string port;
string protocol;
string page;
SOCKET ConnectSocket;
int parseAnnounce(string announce);
int parseTrackerResponse(string response);
};
the vector is declared by this line:
vector<trackerSocket*> trackers;
and the classes are added to the vector using this line:
trackerSocket *temptracker = new trackerSocket();
//Initialize values in temptracker structure here (omitted)
trackers.push_back(temptracker);
//Reset temptracker
temptracker = new trackerSocket();
//Initialize values in temptracker structure here (omitted)
trackers.push_back(temptracker);
//Repeat
How can I access the working variable of each class in the vector? The following code does not print working at all even though I know some of the classes have it set to true.
for(i = 0; i < trackers.size(); i++){
if(trackers[i]->working){
printf("Working.\n");
}
}
Thanks for your help :)