Qbasicnews.com

General => General Programming => Topic started by: wallace on April 07, 2006, 11:52:03 AM



Title: C++ problem
Post by: wallace on April 07, 2006, 11:52:03 AM
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?


Title: C++ problem
Post by: thegrogen on April 07, 2006, 05:49:35 PM
Did you remember to provide a function prototype BEFORE the template stuff?


Title: C++ problem
Post by: wallace on April 07, 2006, 07:43:16 PM
The second line of code.


Title: C++ problem
Post by: Ryan on April 07, 2006, 08:46:47 PM
Exactly.. that's after the include.  Does this not matter in C++?


Title: C++ problem
Post by: na_th_an on April 07, 2006, 10:37:04 PM
It should. An include just pastes code. So, technically, that prototype is after the template definition.


Title: C++ problem
Post by: wallace on April 09, 2006, 11:21:58 AM
oh *smacks self*