Sorry for the repeat post! I posted here first. Then I found the General C++ Programming section, and thought that would be a better place for the post. PLEASE DELETE THIS THREAD!
It shouldn't make a difference if you pass a string literal or a string object - the string literal will be implicitly converted to a string.
There's an important step you're missing - though it won't help you with your compilation error: You're not catching / handling the thrown exception!
If you take a look at how 'error' is implemented, it's just wrapper for throwing a runtime error. You'll have to handle the exception in a try-catch block.
I don't know why you're getting a compilation error. The following code works for me: