|
Boost Users : |
From: Kevin Martin (kev82_at_[hidden])
Date: 2008-08-02 15:29:48
I'm new to boost::variant and I can't seem to use it in a class
because I get linker errors. I can't find any reference to this in the
archive or the docs so I figure it must be something silly I'm
missing. Any help appreciated. The compilation command, error, and
files are shown below.
Thanks,
Kevin Martin
g++ -I $BOOSTINC test.cpp a.cpp
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../x86_64-suse-
linux/bin/ld:
`
.gnu
.linkonce
.t
._ZN5boost6detail7variant15visitation_implIN4mpl_4int_ILi0EEENS1_20visitation_impl_stepINS_3mpl6l_iterINS7_6l_itemINS3_5long_ILl2EEEiNS9_INSA_ILl1EEESsNS7_5l_endEEEEEEENS8_ISD_EEEENS1_9destroyerEPvNS_7variantIiSsNS1_5void_ESM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_E18has_fallback_type_EEEN7Visitor11result_typeEiiRSP_T2_NS3_5bool_ILb0EEET3_PT_PT0_
' referenced in section `.rodata' of /tmp/ccZwRSZE.o: defined in
discarded section
`
.gnu
.linkonce
.t
._ZN5boost6detail7variant15visitation_implIN4mpl_4int_ILi0EEENS1_20visitation_impl_stepINS_3mpl6l_iterINS7_6l_itemINS3_5long_ILl2EEEiNS9_INSA_ILl1EEESsNS7_5l_endEEEEEEENS8_ISD_EEEENS1_9destroyerEPvNS_7variantIiSsNS1_5void_ESM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_SM_E18has_fallback_type_EEEN7Visitor11result_typeEiiRSP_T2_NS3_5bool_ILb0EEET3_PT_PT0_
' of /tmp/ccZwRSZE.o
The files are:
==== a.h ====
#ifndef __A_HEADER__
#define __A_HEADER__
#include <boost/variant.hpp>
#include <string>
class A
{
boost::variant<int, std::string> a;
public:
void setToString(const std::string &x);
void setToInt(int x);
int which() const;
};
#endif
==== a.cpp ====
#include "a.h"
int
A::which() const
{
return this->a.which();
}
void
A::setToString(const std::string &x)
{
this->a = x;
}
void
A::setToInt(int x)
{
this->a = x;
}
==== test.cpp ====
#include "a.h"
#include <iostream>
int main() {
A a;
a.setToString("abc");
std::cout << a.which() << std::endl;
a.setToInt(123);
std::cout << a.which() << std::endl;
return 0;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net