Qbasicnews.com

Full Version: C++ problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
#include "Wrapper.h"
int Compare(int, int);

int main(){
  //stuff
}

int Compare(int x, int y){
  if (x == y)
      return 0
  else
      return 1
}

Wrapper inherites from object where Compare is declared as pure virtual. In Wrapper.cpp I have an error here:

Code:
template <class datatype>
int Wrapper<datatype>::CompareTo (Object const & obj) const {    Wrapper<datatype> const & arg = dynamic_cast<Wrapper<datatype> const &> (obj);
    // comparing wrapped datatype, not objects, so need to cast    
    return :: Compare (datum, arg.datum);
    // :: Compare(...) is global and define in the driver program
}

The error is on the return command saying that Compare has not been declared. What's going on?
Did you remember to provide a function prototype BEFORE the template stuff?
The second line of code.
Exactly.. that's after the include. Does this not matter in C++?
It should. An include just pastes code. So, technically, that prototype is after the template definition.
oh *smacks self*