Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this considered constant?

Tags:

c++

utf-8

I have a stack of UTF8 characters:

stack<wchar_t> tokenStack;

i try to add to it like this:

void doLeftParen() { tokenStack.push( L"(" ) }

but the compiler doesn't like it:

$ g++ PropositionalLogic.cpp -o PropositionalLogic

PropositionalLogic.cpp:27:39: error: reference to type 'const value_type' (aka 'const wchar_t') could not bind to an lvalue of type 'const wchar_t [2]' void doLeftParen() { tokenStack.push( L"(" ) }

I tried searching for the error, but came up empty. I'm not really sure what else i should be searching for. I've also tried just adding a regular ASCII character, but same error. How can i add characters to this stack?

like image 442
David Avatar asked Dec 09 '25 06:12

David


1 Answers

You're trying to push a string not a char, changing the double quotes to single quotes will make it work, also you're missing a semi-colon at the end of the push function

void doLeftParen() { tokenStack.push( L'(' ); }
like image 133
Khaled Mohamed Avatar answered Dec 11 '25 18:12

Khaled Mohamed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!