How to use pure virtual functions as a prototype in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

class number {
protected:
	int value;
public:
	void set(int _value) { value = _value; }
	virtual void show() = 0; // pure virtual function
};

class hexClass : public number {
public:
	void show() {
		cout << std::hex << value << endl;;
	}
};


class octClass : public number {
public:
	void show() {
		cout << std::oct << value << endl;
	}
};

int main()
{
	hexClass h;
	octClass o;

	h.set(131);
	h.show(); 

	o.set(180);
	o.show();  

	return 0;
}


/*
run:

83
264

*/

 



answered Apr 3, 2018 by avibootz

Related questions

1 answer 162 views
3 answers 185 views
185 views asked Jan 29, 2023 by avibootz
1 answer 170 views
1 answer 164 views
1 answer 162 views
1 answer 171 views
...