Questo compila:Utilizzando boost :: :: assegnare LIST_OF
std::vector<int> value = boost::assign::list_of(1)(2);
Ma non questa:
Constructor(std::vector<int> value)
{
}
Constructor (boost::assign::list_of(1)(2));
Esiste una soluzione one-liner per inizializzare il vettore passato al costruttore?
Meglio ancora, se le copie costruttore per una variabile di classe prendendo un riferimento invece:
Constructor(std::vector<int>& value)
{
_value = value;
}
UPDATE
Se provo il seguente:
enum Foo
{
FOO_ONE, FOO_TWO
};
class Constructor
{
public:
Constructor(const std::vector<Foo>& value){}
};
Constructor c(std::vector<Foo>(boost::assign::list_of(FOO_ONE)));
ottengo l'errore del compilatore:
error C2440: '<function-style-cast>' : cannot convert from 'boost::assign_detail::generic_list<T>' to 'std::vector<_Ty>'
1> with
1> [
1> T=Foo
1> ]
1> and
1> [
1> _Ty=Foo
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
È possibile fornire il messaggio di errore del compilatore? –
@Kevin MOLCARD Aggiunto errore del compilatore – Baz
[Sembra che questo sia l'errore] (https://svn.boost.org/trac/boost/ticket/7364). –