2

I have the following code

  template<typename VP,bool b>
  class ValueProcessor{
    template<typename Access,typename X> void processValue(X& x){}
  };


  template<typename VP>
  class ValueProcessor<VP,true>{
  public:
    template<typename Access,typename X> void processValue(X& x);
  };

  template<typename VP>  
  template<typename Access,typename X> 
  void ValueProcessor<VP,true>::processValue(X& x){
    class Updater{
      ValueProcessor<VP,false> valPro;
      X x;
    public:
      void operator()(){
        valPro.processValue<Access,X>(x);
      };
    };
  }

but it fails with this error

    source>: In member function 'void ValueProcessor<VP, true>::processValue(X&)::Updater::operator()()':
<source>:23:32: error: expected primary-expression before ',' token
   23 |      valPro.processValue<Access,X>(x);
      |      

                      ^

How can I refer to Access from the inner class?

Fabio Dalla Libera
  • 1,297
  • 1
  • 10
  • 24

1 Answers1

3

As pointed out in the comment the solution is to add a .template discrimitaor before the member function name:

valPro.template processValue<Access,X>(x);

This is necessary because the type of ValueProcessor<VP,false> valPro is a dependent type (i.e. it's actual type depends on the type of the template parameter VP) the c++ language requires to add the .template disambiguator if you want to call a template member function of VP. Otherwise the parser would interpret the opening < as less-than operator.

See cppreference for a more in-depth discussion. The template disambiguator is described at the very end of that article.

florestan
  • 4,405
  • 2
  • 14
  • 28