Question about implementing abstract functions in C++? -
i learning , testing piece of c++ code follows:
#include "stdafx.h" #include <iostream> using namespace std; #include <conio.h> #include <cstring> class shape { public: shape() {}; ~shape() {}; virtual void display() const = 0; virtual double volume() const = 0; }; class square : public shape { public: square() {}; ~square() {}; void display() const; double volume() const; }; void square::display() const { cout << "square!!!!!!!!!!!!!!" << endl; } double square::volume() const { cout << "square volume........." << endl; return 0.0; } int _tmain(int argc, _tchar* argv[]) { shape *s; s = new square; // error here (*s).display(); return 0; }
the above code not compile successfully. produces: "fatal error lnk1120: 1 unresolved externals". can me out that? using ms vs c++ 2005. thanks
the above code compiles , runs on vs 2010 ideone.
check this
there nothing wrong in way have implemented abstract functions in above snippet.
Comments
Post a Comment