Compile error with std::bitset and strings
< Newer Topic
:: Older Topic >
Pages:<< prev 1 next >>
#1 Nov 1, 2014 3:01 pm
Black Hand
GroupAdministrators
Posts3,706
JoinedJan 1, 2002
Figured since I was of a mind to be fixing stuff up I'd get the Smaug 1.8 variables code to actually work right in AFKMud. I've run into one last small problem though.
That error is generated from this code:
According to http://www.cplusplus.com/reference/bitset/bitset/bitset/ I should be able to assign a std::bitset value via a string. Obviously the compiler disagrees, so I'm wondering what I'm missing here. It's the last hurdle left to overcome for this to compile all the way through.
arthmoor@boralis:~/afkmud/src$ make Building AFKMud.... make -j2 -s afkmud Compiling o/variables.o.... variables.cpp: In function ‘void fread_variable(char_data*, FILE*)’: variables.cpp:587:39: error: no match for call to ‘(std::bitset<128ul> (std::string&’ pvd->varflags( varbits ); ^ make[1]: *** [o/variables.o] Error 1 make: *** [all] Error 2 arthmoor@boralis:~/afkmud/src$
That error is generated from this code:
case 'F': if( !str_cmp( word, "Flags" ) ) { string varbits; fread_string( varbits, fp ); pvd->varflags( varbits ); break; } break;
According to http://www.cplusplus.com/reference/bitset/bitset/bitset/ I should be able to assign a std::bitset value via a string. Obviously the compiler disagrees, so I'm wondering what I'm missing here. It's the last hurdle left to overcome for this to compile all the way through.
#2 Nov 1, 2014 11:41 pm
Magician
GroupMembers
Posts132
JoinedJan 29, 2006
pvd->varflags( varbits );
You're attempting to call operator() here, which bitset doesn't have. You can't actually assign strings to a bitset. You can, however, construct one from a string. So you can do the following:
pvd->varflags = std::bitset<128ul>( varbits );
#3 Nov 2, 2014 1:43 am
Black Hand
GroupAdministrators
Posts3,706
JoinedJan 1, 2002
Constructing one from a string is exactly what I was after, and that worked. So thanks. No more compile failure
I just hope it actually assigns them in the same order the characters in the string are written, cause there's conflicting information out there saying I may or may not need to reverse the string before sending it to the bitset constructor.
I just hope it actually assigns them in the same order the characters in the string are written, cause there's conflicting information out there saying I may or may not need to reverse the string before sending it to the bitset constructor.
Pages:<< prev 1 next >>