1

I have a class that looks like this:

template <typename P>
class Pack {
    Public:
          template <typename X>
    Private:
          Other T <other>
};

I want to write the function outside of the class but I am having difficulties defining the header.. I tried something like this:

template <typename X>
int Pack<X>::pop(X led) const{
  // Do something in here with Other from the private above
}

But this does not work it keeps saying "Out of line definition of pop, does not match any definitions of P.

Any help is appreciated thanks!

Clarification: Trying to Implement the function stub so I can write the code outside of the class.

chatycat99
  • 109
  • 1
  • 10
  • `Public:` and `template ` are very strange inside a class declaration. – Constructor Apr 16 '14 at 20:30
  • Not completely sure what your problem is, but maybe this helps: http://stackoverflow.com/questions/22763270/what-is-the-difference-between-two-template-types-and-two-template-parameter-lis/22763450#22763450 – chris Apr 16 '14 at 20:31
  • I agree but there is really no way for me to change around that – chatycat99 Apr 16 '14 at 20:31

1 Answers1

5

Your code looks incomplete and you're posting small chunks of it from time to time but I believe this syntax is what you want:

#include <iostream>
using namespace std;

template <typename P>
class Stack {
    public:
          template <typename X> int pop(X pred) const;
};

template <typename P> 
template<typename X>
int Stack<P>::pop(X pred) const{
    return 0;
}

int main() {

    Stack<bool> obj;
    char a;
    obj.pop(a);

    return 0;
}

http://ideone.com/Cp69hg

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • @user2577829 Glad that I helped. Don't forget to mark this as the answer if this is what you were looking for. – Marco A. Apr 16 '14 at 20:35