Boost logo

Boost Users :

Subject: Re: [Boost-users] statechart] [gcc-4.7.2] a template state inherited from statechart::state results in compiler error
From: Igor R (boost.lists_at_[hidden])
Date: 2013-01-15 06:59:19


> I'm using Boost.Statechart and have come across a strange gcc-4.7.2 behavior on the attached sample code. The error is:
>
> cpp-lab/boost/statechart/main.cpp:89:23: error: expected ')' before 'ctx'
>
> If outermost_context() isn't used in Inner3() constructor and statechart::simple_state is used instead of statechart::state everything is OK.
> If Inner3 is not a template then everything is OK
>
> The problem occurs only if a state template class is inherited from statechart::state.
>
> Is there any workaround for the issue?

You can't use unqualified inherited names from within a template,
because the compler wouldn't search them in the base.
Try something like this:

template<class T>
struct Inner3: public sc::state<Inner3<T>, Active>
{
    Inner3(typename sc::state<Inner3<T>, Active>::my_context ctx):
sc::state<Inner3<T>, Active>::my_base(ctx)
    {
        std::cout << "Inner3(): my outermost_context() is '" <<
this->outermost_context().name() << "'" << std::endl;
    }

    ~Inner3() {
        std::cout << "~Inner3()"<< std::endl;
    }
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net