Login
User Name:

Password:



Register

Forgot your password?
IPv6
Jan 25, 2025 10:45 pm
By Samson
mudstrlcpy and mudstrlcat
Jan 18, 2025 5:23 pm
By Samson
I3 and IMC
Jan 17, 2025 9:35 pm
By Samson
AFKMud 2.5.1
Jan 17, 2025 2:22 pm
By Samson
Array out of bounds ?
Jan 16, 2025 4:48 am
By Remcon
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
AFKMud 2.5.1
Author: AFKMud Team
Submitted by: Samson
Kayle's Weather Code for AFKMud
Author: Kayle
Submitted by: Samson
AFKMud 2.5.0
Author: AFKMud Team
Submitted by: Samson
SWFotEFUSS 1.5.2
Author: Various
Submitted by: Samson
Users Online
Anthropic, GPTBot, AhrefsBot, Yandex

Members: 0
Guests: 3
Stats
Files
Topics
Posts
Members
Newest Member
503
3,811
19,714
589
xhuul

» SmaugMuds » Codebases » AFKMud Support & Development » Compile error with std::bitse...
Forum Rules | Mark all | Recent Posts

Compile error with std::bitset and strings
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Nov 1, 2014 3:01 pm   
Go to the top of the page
Go to the bottom of the page

Samson
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.

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.

Post is unread #2 Nov 1, 2014 11:41 pm   
Go to the top of the page
Go to the bottom of the page

Caius
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 );

Post is unread #3 Nov 2, 2014 1:43 am   
Go to the top of the page
Go to the bottom of the page

Samson
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.

Pages:<< prev 1 next >>