mardi 30 décembre 2014

Getting c++11 auto initialization syntax right

I am newbie programmer in C++ (but a veteran programmer in other languages) and I am trying to use "Modern C++" in my code.


I am wondering what I am doing wrong here, trying to initialize an istream from a boost::asio::streambuf:



#include <iostream>
#include <boost/asio/streambuf.hpp>

class A {
public:
void foo();
private:
boost::asio::streambuf cmdStreamBuf_{};
};

void A::foo() {
std::istream is1{&cmdStreamBuf_}; // works
auto is2 = std::istream{&cmdStreamBuf_}; // does not compile
}


I get this error:



try.cpp:13:41: error: use of deleted function 'std::basic_istream<char>::basic_istream(const std::basic_istream<char>&)'


I am not trying to copy; I thought I was constructing an std::istream!


Aucun commentaire:

Enregistrer un commentaire