interpreting messages from compiler diags
Jonathan Wakely
jwakely.gcc@gmail.com
Sat Jun 14 20:55:00 GMT 2014
On 14 June 2014 21:44, Linda Walsh wrote:
> Most of the g++ error messages are pretty helpful, but sometimes
> they use nouns that don't have a clear definition...
>
> In trying various combinations 'static_cast' as in:
>
> [ltask.h:]
> class Task {
> public:
> function<void(void)>work{};[ltask.h]
> ...
> [meter.h:]
> class Meter: public Task {
> ...
>
> [meter.cc including ltask.h:]
> work = static_cast<void>(Task::*())(&Meter::checkResources);
I have no idea what this is meant to be.
static_cast<T>(x) means cast the expression x to T, so you are trying
to cast something to void, which can't be on the RHS of an assignment.
The something you're trying to cast is Task::*() which is not an
expression. It's not anything, it's invalid syntax.
Maybe you mean something like static_cast<void
(Task::*)()>(&Meter:checkResources) but:
1) the cast should be unnecessary, that conversion can happen implicitly
2) you can't assign a void (Task::*)() to a std::function<void()>
because you need an object to call a member function on, and you
haven't provided one.
Try:
work = std::bind(&Meter::checkResources, this);
> --- errors:
> g++: COMPILE meter.cc
> meter.cc: In constructor ‘Meter::Meter(XOSView*, const char*, const char*,
> bool, bool, bool)’:
> meter.cc:23:33: error: expected unqualified-id before ‘*’ token
> work = static_cast<void>(Task::*())(&Meter::checkResources);
> ^
> meter.cc:23:35: error: expected primary-expression before ‘)’ token
> work = static_cast<void>(Task::*())(&Meter::checkResources);
>
> ----
>
> I.e. 'task' defines a "work" pointer to be done.
No it doesn't, it has a member of type std::function<void()>, that's
not any kind of pointer.
> Since Meter is a strict superset of Task (w/Task declared public), I should
> (as I understand it) be able to cast a pointer of a meter into a task and
> vice-versa if the underlying object is really a meter.
> My problem is getting the syntax of this type interpretation to work, but
> not knowing the error messages in c++ well enough to know what it
> wants. i.e. "unqualified-id"? "primary-expression"? What are those
> and how woudl they differ from qualified or non-primary??
>
> The error messages are great, if I know all the 'nouns' that they refer
> to! At times like this I would wish for some more verbose error messages
> that explain what the terms are -- or hyperlinked error messages...(in my
> tty window? hmmm). Well, hopefully you get the idea.
>
> Where can I look up all these 'nouns' to find out what they mean?
The C++ standard.
More information about the Libstdc++
mailing list