I'm getting the following error when I compile:
Here's a look at the files in question:Code:error: 'virtual const int Base::getX() const' and 'virtual const int Base::getY() const' cannot be overloaded
main.cpp
derived.hCode:#include <iostream> #include "derived.h" int main(){ Derived( 1, 1 ); return 0; }
derived.cppCode:#ifndef DERIVED_H_ #define DERIVED_H_ #include <iostream> class Base{ public: Base( int x, int y ) : x(x), y(y) {} virtual const int getX() const = 0; // Error is with these two lines virtual const int getY() const = 0; protected: int x, y; }; class Derived : public Base{ public: Derived( int x, int y ); const int getX() const; const int getY() const; const int getZ() const; friend std::ostream& operator<<( std::ostream& os, const Derived& d ); friend class Modifier; private: int z; void setZ( int val ); }; #endif
Code:#include "derived.h" Derived::Derived( int x, int y ) : Base(x,y), z( x ) {} const int Derived::getX() const{ return x; } const int Derived::getY() const{ return y; } const int Derived::getZ() const{ return z; } void Derived::setZ( int val ){ z = val; } std::ostream& operator<<( std::ostream& os, const Derived& d ){ os << d.x << " " << d.y << " " << d.z; return os; }



LinkBack URL
About LinkBacks



