There are character literals (with '
) and string literals (with "
). Character literals have one character. String literals are arrays of characters. You can’t write something like 'plus'
because it has more than one character (well technically you can, but it’s a multi-character literal, but lets not go there).
Nonetheless, this wouldn’t make any sense because operationptr
points at a single char
object. A single char
can’t contain the entire word plus
.
If you want to be able to accept plus
as input, then I suggest you start using strings. In fact, use std::string
.
As a side note, you are using pointers and dynamic allocation far too often. You are also forgetting to delete
the objects that you create with new
– this is a memory leak. I imagine you have come from a language that uses new
for all object creation. In C++, this is not necessary (and is not a good practice). Instead, you can declare objects like so:
float aptr;
There is no need to dereference this object. You can just use aptr
directly as a float
.