ofxTCPClient cannot be put in vector?

i need to setup several ofxTCPClient in one app, so i want to use an vector to store them. the code is:


#pragma once
#include "ofMain.h"
#include "ofxNetwork.h"

class ofApp : public ofBaseApp{

		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);

		std::vector<ofxTCPClient> tcpClients_;

#include “ofApp.h”

void ofApp::setup(){
    ofxTCPClient tcpClient;
	tcpClient.setup("", 8000);

however, there are compile errors say: error C2248: “ofxTCPManager::ofxTCPManager”: unable to visit private member(declared in “ofxTCPManager”)

Hi yangyangcv,

This is because ofxTCPClient is using ofThread. It it unsafe to store ofxTCPClient instances in a std::vector because of the way a vector moves things in memory. Instead you can store a pointer to an instance in the vector.

When I try your code XCode gives me this message “Call to implicitly-deleted copy constructor of ‘ofxTCPClient’”

This would be my suggestion:

class ofApp : public ofBaseApp{
	void setup();
	std::vector<ofxTCPClient*> tcpClients_;

void ofApp::setup(){
  ofxTCPClient *tcpClient = new ofxTCPClient();
  tcpClient->setup("", 8000);

int main() {
	ofRunApp(new ofApp());

fantastic! it works!