boost::variant: need help with 'get'
I'm trying to use the "get" template with boost::variant but can't figure out how to get my compiler to recognize it. Here's a simple test program: --- #include <iostream> #include <cmath> #include <string> #include <boost/variant.hpp> using namespace boost; using namespace std; typedef variant<int, double, string> elem_t; int main () { elem_t pi = M_PI; double d = get (pi); cout << "pi =~ " << d << endl; return 0; } --- But my compiler (gcc 3.3.2) tells me: g++ -I/home/tools/boost-1.31.0 test.cpp -o test test.cpp: In function `int main()': test.cpp:15: error: no matching function for call to `get(elem_t&)' I'm using Boost 1.31.0. Thanks for any help, -- Caleb Epstein | bklyn . org | The Golden Rule of Arts and Sciences: cae at | Brooklyn Dust | He who has the gold makes the rules. bklyn dot org | Bunny Mfg. |
On Friday 28 May 2004 20:43, Caleb Epstein wrote:
typedef variant<int, double, string> elem_t;
int main () { elem_t pi = M_PI; double d = get (pi);
If my understanding is correct, "get" expects the desired result type to be specified explicitly. In fact, how should the compiler deduce the return type of "get" otherwise? So you need to write: double d = get<double>(pi); Regards, Wolfgang Meyer
On Fri, May 28, 2004 at 11:38:15PM +0000, Wolfgang Meyer wrote:
If my understanding is correct, "get" expects the desired result type to be specified explicitly. In fact, how should the compiler deduce the return type of "get" otherwise? So you need to write: double d = get<double>(pi);
Thanks. This works. I missed the example usage of get<T> in the documentation. -- Caleb Epstein | bklyn . org | Without love intelligence is dangerous; cae at | Brooklyn Dust | without intelligence love is not enough. bklyn dot org | Bunny Mfg. | -- Ashley Montagu
participants (2)
-
Caleb Epstein
-
Wolfgang Meyer