Initializing without assigning
Coming from writing mostly in Java, I have trouble understanding how to
declare a member without initializing it, and do that later... In Java,
I would write something like
public static void main(String[] args) {
MyType aMember;
...
aMember = new MyType(...)
...
}
However, in C++ this does not seem to work. I declare in class (it's
for serial port communication) like this:
#include <fstream>
#include <boost/thread/thread.hpp>
class COMConn {
public:
COMConn(int port);
~COMConn();
char *send(char);
char *send(char, char[]);
private:
void connect(int);
std::ifstream input;
std::ofstream output;
boost::thread inputthread;
boost::thread outputthread;
};
But when I want to initialize the threads and streams, I want to do
something like
void COMConn::connect(int port) {
this->input = std::ifstream("COM1:");
this->inputthread = boost::thread(&input.read); // Not correct, needs
arguments, but skip that for now
//etc for the others
}
How do you go about doing this in C++? I found that I could do
this->input.open("COM1:");
But that is hardly something that will work in general. I find this
very confusing I must say... Thanks you for any advice