some changes ; mostly new examples
This commit is contained in:
22
OOP/methodes/car_speed.cpp
Normal file
22
OOP/methodes/car_speed.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
This here that we have is just another demo of the OOP in c++ ; we have the function that we have in the last example and then we usefully do something
|
||||
with this function ;
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Car {
|
||||
public:
|
||||
int speed(int max_speed);
|
||||
};
|
||||
|
||||
int Car::speed(int max_speed) {
|
||||
return max_speed;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Car volvo;
|
||||
volvo.speed(600);
|
||||
}
|
||||
23
OOP/methodes/class_methode_outside.cpp
Normal file
23
OOP/methodes/class_methode_outside.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
Here we have a Class which has a Function that is declared outside of the Class itself ;
|
||||
We just reference the Function inside the class and later outside create a Function with this structure:
|
||||
class::function()
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
class outside {
|
||||
public:
|
||||
void coolFunc();
|
||||
};
|
||||
|
||||
void outside::coolFunc() {
|
||||
cout << "I am a cool Outside Function\n";
|
||||
};
|
||||
|
||||
int main() {
|
||||
outside classobj;
|
||||
classobj.coolFunc(); // No cout needed here for some reason ; idk why
|
||||
}
|
||||
19
OOP/methodes/class_methodes.cpp
Normal file
19
OOP/methodes/class_methodes.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
/*
|
||||
Within a Class you can define Functions (called Methodes) ; you can define these to all datatypes you want but just be careful to not segfault
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MethodConstruction {
|
||||
public:
|
||||
void myCoolFunction() {
|
||||
cout << "I am a very Cool Function and I got called!\n";
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
MethodConstruction classobj;
|
||||
classobj.myCoolFunction();
|
||||
return 0;
|
||||
}
|
||||
23
OOP/methodes/simple.cpp
Normal file
23
OOP/methodes/simple.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* So basically a class is a template for data you can use anywhere ; so here you can def myVar to a int and a string to mystring and later output
|
||||
that into a Object of that class (marked later in program)
|
||||
*/
|
||||
class MyClass {
|
||||
public:
|
||||
int myVar;
|
||||
string myString;
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
||||
MyClass classobj1;
|
||||
classobj1.myString = "You*re gay";
|
||||
classobj1.myVar = 25565;
|
||||
|
||||
cout << classobj1.myString << "\n" << classobj1.myVar;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user