?
=?ISO-8859-1?Q?Mattias_Br=E4ndstr=F6m?=
Hello all!
I am trying to write code that allows me to initialise one of my classes
inline (with a vector like structure). Inline might not be the best
term to use here but I can't think of any other right now. Here is my code:
template <typename T>
class Array {
public:
Array& operator()(const T& v) {
a.push_back(v);
return *this;
}
Array& foo(const T& v) {
return *this;
}
private:
std::vector<T> a;
};
class M {
public:
M(const Array<char>&) { }
};
int main() {
M m(Array<char>()(0)(1)(2)(1)); // XXX
return 0;
}
At the line marked with XXX you can see what I want to accomplish. My
problem is that this won't compile. However, if I call Array::foo()
instead of operator() it compiles fine. This confuses me. Maybe someone
on this list can enlighten me as to what is happening.
Regards,
Mattias
I am trying to write code that allows me to initialise one of my classes
inline (with a vector like structure). Inline might not be the best
term to use here but I can't think of any other right now. Here is my code:
template <typename T>
class Array {
public:
Array& operator()(const T& v) {
a.push_back(v);
return *this;
}
Array& foo(const T& v) {
return *this;
}
private:
std::vector<T> a;
};
class M {
public:
M(const Array<char>&) { }
};
int main() {
M m(Array<char>()(0)(1)(2)(1)); // XXX
return 0;
}
At the line marked with XXX you can see what I want to accomplish. My
problem is that this won't compile. However, if I call Array::foo()
instead of operator() it compiles fine. This confuses me. Maybe someone
on this list can enlighten me as to what is happening.
Regards,
Mattias