Reputation: 866
I am trying to use Boost::assign and the operator += to initialize a static set that I am planning to use later. I followed the steps specified in this link. The code is split across three files
/*Assign.hpp*/
#ifndef __SAMPLE_CLASS__
#define __SAMPLE_CLASS__
#include <iostream>
#include <set>
#include <string>
#include <boost/assign/std/set.hpp>
class SampleClass
{
public:
SampleClass();
~SampleClass();
typedef std::set<int> SET_TYPE;
static const SET_TYPE my_set1;
static const SET_TYPE my_set2;
};
#endif
/*Assign.cpp*/
#include "assign.hpp"
using namespace boost::assign;
const SampleClass::SET_TYPE SampleClass::my_set1 += 1,2,3;
const SampleClass::SET_TYPE SampleClass::my_set2 += 4,5,6;
SampleClass::SampleClass()
{
}
SampleClass::~SampleClass()
{
}
/*main.cpp*/
#include "assign.hpp"
int main()
{
SampleClass sobj;
return 0;
}
I get the following compilation error when I issue the following command
g++ -I /usr/local/include main.cpp assign.cpp
Error snippet
assign.cpp:6:50: error: invalid '+=' at end of declaration; did you mean '='?
const SampleClass::SET_TYPE SampleClass::my_set1 += 1,2,3;
^~
=
assign.cpp:6:42: error: no viable conversion from 'int' to 'const SampleClass::SET_TYPE' (aka 'const set<int>')
const SampleClass::SET_TYPE SampleClass::my_set1 += 1,2,3;
^ ~
assign.cpp:6:55: error: expected unqualified-id
const SampleClass::SET_TYPE SampleClass::my_set1 += 1,2,3;
^
assign.cpp:6:55: error: expected ';' after top level declarator
const SampleClass::SET_TYPE SampleClass::my_set1 += 1,2,3;
...
Is there something wrong in the way I am trying to initialize my static set or my usage of the += operator here?
Upvotes: 0
Views: 417
Reputation: 683
You can change it like this if your compiler supports c++11:
const SampleClass::SET_TYPE SampleClass::my_set1 = {1,2,3};
const SampleClass::SET_TYPE SampleClass::my_set2 = {4,5,6};
Upvotes: 0