Reputation: 2035
I have a situation where I am not allowed to modify the header file for my class. I want to add just a helper function to use with one of my functions.. but cant quite figure out the correct way to implement it. Normally I try google but couldn't find any help on there.
Here is my current code:
template<typename T>
void Set<T>::doubleRotateRight(Elem *& node) {
// you fill in here
rotateRight(node->left);
rotateLeft(node);
//call private helper not defined in header
privmed();
}
void privmed(){
//out << "who" << endl;
}
However, when I run this I get the error:
error: there are no arguments to ‘privmed’ that depend on a template parameter, so a declaration of ‘privmed’ must be available [-fpermissive]
privmed();
Any help with this would be incredible!
Upvotes: 0
Views: 528
Reputation: 6166
I think the problem is that you have to define the "privmed()" function before you use it, like this:
void privmed(){
//out << "who" << endl;
}
template<typename T>
void Set<T>::doubleRotateRight(Elem *& node) {
// you fill in here
rotateRight(node->left);
rotateLeft(node);
//call private helper not defined in header
privmed();
}
Upvotes: 1
Reputation: 145457
You can just use a lambda:
template<typename T>
void Set<T>::doubleRotateRight(Elem *& node)
{
static auto const privmed = []() -> void
{
//out << "who" << endl;
};
// you fill in here
rotateRight(node->left);
rotateLeft(node);
//call private helper not defined in header
privmed();
}
Upvotes: 1