Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ problem
#1
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?
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#2
Did you remember to provide a function prototype BEFORE the template stuff?
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Reply
#3
The second line of code.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#4
Exactly.. that's after the include. Does this not matter in C++?
Reply
#5
It should. An include just pastes code. So, technically, that prototype is after the template definition.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
oh *smacks self*
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)