0

This could be an easy answer to what I am facing, but I have tried my best the search previous posts, but none directly maps to what I need. The code below has a master (bmGsNoSuff) and slave (bmGsNoSuffHelper) . The Idea is, I want to pass the variable j from bmGsNoSuff such that it gets used by the inner called struct bmGsNoSuffHelper . It turns out, I cannot do this so long as j has been declared as a parameter of bmGsNoSuff's constructor. The compiler alarms : error: ‘j’ cannot appear in a constant-expression bmGsNoSuffHelper<I,j>()(BmGs, suff, i );

What could be the way out of this? How can I pass j from the master to the helper?

 template<typename I , int j>
    struct bmGsNoSuffHelper
    {
            void operator () ( I BmGs[], I suff[] ,int i )
            {
               if ( j < size - 1 -i ){
                   if(BmGs[j]==size){
                      BmGs[j]=size-1-i;
                    }
                    bmGsNoSuffHelper<I,j+1>()(BmGs, suff, i  ); // InitialiseBmGs<I,i+1> () ( BmGs);
                }
            }
    };
    template<typename I>
    struct bmGsNoSuffHelper<I, size>
    {
           void operator () (I BmGs[], I suff[], int i  )   {}
    };


    //BmGsNoSuff
    template<typename I , int i>
    struct bmGsNoSuff
    {
            void operator () ( I BmGs[], I suff[], int j )
            {
               if ( i >=-1 ){
                   if((i==-1) || ( suff[i] == i+1)){
                          bmGsNoSuffHelper<I,j>()(BmGs, suff, i  );
                    }
                    bmGsNoSuff<I,i-1>()( BmGs, suff, j + 1  );  
                }
            }
    };
    template<typename I>
    struct bmGsNoSuff<I, -2>
    {
           void operator () (I BmGs[], I suff[] , int j)   {}
    };
Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
Walker
  • 323
  • 1
  • 12
  • Not sure what you're trying to do, but shouldn't `bmGsNoSuffHelper` at least be a template? You specialize it later on, and I don't see where this `j` comes from. Perhaps from the missing template declaration? – JorenHeit Aug 09 '15 at 14:15
  • 1
    Also, in the non-specialized `bmGsNoSuff`, you're using the runtime parameter `j` to instantiate the template `bmGsNoSuffHelper`. – JorenHeit Aug 09 '15 at 14:21
  • @JorenHeit, I had left the template declaration by mistatke , thanks. – Walker Aug 09 '15 at 14:29
  • The idea is to have a way to send ` j` from ` bmGsNoSuff` to `bmGsNoSuffHelper` so the it can do recursive computations bases on the newly passed value. – Walker Aug 09 '15 at 14:31
  • 1
    You can only do that if `j` itself is a constant expression, e.g. a template parameter rather than a function parameter. – JorenHeit Aug 10 '15 at 11:06

0 Answers0