My initialisation of a static const set<string>
appears to be incorrect, I'd appreciate your guidelines on this:
obj.h
:
class obj
{
...
private:
static const set<string> keywords;
...
}
obj.cpp
:
const string kw[] = {"GTR","LTR","LEQ","GEQ","NEQ","SQRT","sqrt"};
const set<string> obj::keywords = (kw,kw + sizeof(kw)/sizeof(kw[0]));
But this yields the error:
error: conversion from ‘const string* {aka const std::basic_string<char>*}’ to non-scalar type ‘const std::set<std::basic_string<char> >’ requested
Can somebody tell me the correct way to initialise this set?
I'm wondering why you're using an array to initialize the std::set
.
You could directly initialize the set as:
const set<string> obj::keywords {"GTR","LTR","LEQ","GEQ","NEQ","SQRT","sqrt"};
That is what you should be doing if you're using a compiler supporting C++11.
As for what is wrong with your code, as the other two answers says, remove =
:
const string kw[] = {"GTR","LTR","LEQ","GEQ","NEQ","SQRT","sqrt"};
const set<string> obj::keywords(kw,kw + sizeof(kw)/sizeof(kw[0]));
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With