Re: I cannot compile a partial initialisation of a template [gcc 6.3.1]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Στις 17/6/2017 01:22, ο Jonathan Wakely έγραψε:
On 16 June 2017 at 22:44, Georgios Petasis via gcc-help
<gcc-help@xxxxxxxxxxx> wrote:
Hi all,

I am trying to compile the following code, I am getting an error, and I am
unable to fix the error.

I am trying to compile this:

template<typename Pattern>
class HasAttributeMatchingValue: public
AnnotationUnaryPredicateWithStates<std::string, Pattern> {
     bool operator() (const ELEP::CDM::Annotation& ann) const {
        return ann.containsAttributeMatchingValue(std::get<0>(m_state),
std::get<1>(m_state));
     };
  };

The error I am getting is:

`m_state` was not declared in this scope: return
ann.containsAttributeMatchingValue(std::get<0>(m_state),
std::get<1>(m_state));

If I use instead:

template<typename Pattern>
class HasAttributeMatchingValue: public
AnnotationUnaryPredicateWithStates<std::string, std::string> {
     bool operator() (const ELEP::CDM::Annotation& ann) const {
        return ann.containsAttributeMatchingValue(std::get<0>(m_state),
std::get<1>(m_state));
     };
  };

It compiles without problem.

AnnotationUnaryPredicateWithStates is a template:

template<class... States> class AnnotationUnaryPredicateWithStates :
      public UnaryPredicateWithStates<ELEP::CDM::Annotation, States ... > {};

template<class Arg, class... States> class UnaryPredicateWithStates :
      public UnaryFunctionWithStates<Arg, bool, States ... > {};

template<class Arg, class Result, class... Ts>
class UnaryFunctionWithStates : public UnaryFunction<Arg, Result> {
     public:
        UnaryFunctionWithStates() = default;
        template <class... Args> UnaryFunctionWithStates(Args&&... args) :
             m_state(std::forward<Args>(args)...) {};
    protected:
         std::tuple<Ts...> m_state;
  };

template<class Arg, class Result> class UnaryFunction {
     public:
        virtual Result operator()(const Arg &) const = 0;
  };

What am I doing wrong?
See https://gcc.gnu.org/wiki/VerboseDiagnostics#dependent_base

Dear Jonathan,

Thank you very much, this solved the problem. I didn't know about it.

Regards,

George




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux