Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
using namespace std; class Shape{ private: int width, length; public: Shape() {} Shape(int _width, int _length) { width = _width; length = _length; } virtual int get_area() = 0; // only signature, the function will be written inside the derived classes int get_widht() { return width; } int get_length() { return length; } }; class Rectangle : public Shape { public: Rectangle(int width, int length) : Shape(width, length) { } int get_area() override { return get_length() * get_widht(); } }; class Square : public Shape { public: Square(int width, int length) : Shape(width, length) { } int get_area() override { return get_length() * get_widht(); } }; int main(){ Shape *rect = new Rectangle(4, 5); Shape *square = new Square(5, 5); cout << rect->get_area() << endl; cout << square -> get_area() << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)