Skip to content

Instantly share code, notes, and snippets.

@jagbolanos
Created August 31, 2013 13:55
Show Gist options
  • Save jagbolanos/6398362 to your computer and use it in GitHub Desktop.
Save jagbolanos/6398362 to your computer and use it in GitHub Desktop.
#include <iostream>
class A {
private:
int a;
public:
static double sa;
A(int _a) {
a = _a;
}
static void contar() {
sa++;
}
virtual int calcular() {
std::cout<<"Calcular A" <<std::endl;
}
};
class B : public A {
private:
int b;
public:
B(int _a, int _b) : A(_a) {
b = _b;
}
};
class C : public B {
private:
float c;
public:
static float sc;
C(int _a, int _b, float _c) : B(_a, _b) {
c = _c;
}
virtual int calcular() {
std::cout<<"Calcular C" <<std::endl;
}
};
void fporvalor(A param1) {
param1.calcular();
}
void fporreferencia(A &param1) {
param1.calcular();
}
void fporobjectsharing(A *param1) {
param1->calcular();
}
int main() {
C c1(1, 2, 3.0);
fporvalor(c1);
fporreferencia(c1);
fporobjectsharing(&c1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment