C with classes
This commit is contained in:
5
ObjectOrientedProgramming/virtualclasstest/a.cpp
Normal file
5
ObjectOrientedProgramming/virtualclasstest/a.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "a.h"
|
||||
|
||||
void A::p(){
|
||||
std::cout << num + plus << std::endl;
|
||||
}
|
||||
23
ObjectOrientedProgramming/virtualclasstest/a.h
Normal file
23
ObjectOrientedProgramming/virtualclasstest/a.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef A_H
|
||||
#define A_H
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
private:
|
||||
int num;
|
||||
int plus;
|
||||
public:
|
||||
A() = delete;
|
||||
A(int n = 10, int m = 5) : num(n),plus(m){}
|
||||
int retNum(){
|
||||
return num;
|
||||
}
|
||||
int retPlus(){
|
||||
return plus;
|
||||
}
|
||||
virtual void p();
|
||||
virtual ~A(){}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
13
ObjectOrientedProgramming/virtualclasstest/b.cpp
Normal file
13
ObjectOrientedProgramming/virtualclasstest/b.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "b.h"
|
||||
#include <iostream>
|
||||
|
||||
void B::p()
|
||||
{
|
||||
int sm = this->retNum() + this->retPlus() + js;
|
||||
std::cout << sm << std::endl;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, B& x){
|
||||
os << x.js << " ";
|
||||
return os;
|
||||
}
|
||||
19
ObjectOrientedProgramming/virtualclasstest/b.h
Normal file
19
ObjectOrientedProgramming/virtualclasstest/b.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef B_H
|
||||
#define B_H
|
||||
|
||||
#include <iostream>
|
||||
#include "a.h"
|
||||
class B : virtual public A{
|
||||
private:
|
||||
A* base;
|
||||
int js;
|
||||
public:
|
||||
B() = delete;
|
||||
B(int n = 1) : A(12,6), base(this), js(n){}
|
||||
void p() override ;
|
||||
friend std::ostream& operator<<(std::ostream& os , B& x);
|
||||
~B(){}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
8
ObjectOrientedProgramming/virtualclasstest/c.h
Normal file
8
ObjectOrientedProgramming/virtualclasstest/c.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
class v{
|
||||
private:
|
||||
int vn;
|
||||
public:
|
||||
virtual void blast() = 0;
|
||||
};
|
||||
16
ObjectOrientedProgramming/virtualclasstest/main.cpp
Normal file
16
ObjectOrientedProgramming/virtualclasstest/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include "a.h"
|
||||
#include "b.h"
|
||||
#include "c.h"
|
||||
|
||||
int main(){
|
||||
v a();
|
||||
A a1(1,2), a2(2,3);
|
||||
B b1(3), b2(5);
|
||||
a1.p();
|
||||
a2.p();
|
||||
b1.p();
|
||||
b2.p();
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user