Add .gitignore and IntelliJ IDEA project configuration files and projects for cpp intro, pointers and classes
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION 4.1)
|
||||
project(classes)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(classes
|
||||
main.cpp
|
||||
ClassA.cpp
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "ClassA.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void ClassA::Print()
|
||||
{
|
||||
std::cout << "ClassA" << std::endl;
|
||||
}
|
||||
|
||||
int ClassA::CompareTo(IComparable *other) {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CLASSES_CLASSA_H
|
||||
#define CLASSES_CLASSA_H
|
||||
#include "IComparable.h"
|
||||
|
||||
|
||||
class ClassA : public IComparable {
|
||||
// private
|
||||
|
||||
public:
|
||||
// public
|
||||
void Print();
|
||||
int CompareTo(IComparable* other) override;
|
||||
|
||||
protected:
|
||||
// protected
|
||||
|
||||
private:
|
||||
// private
|
||||
int _number = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif //CLASSES_CLASSA_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef CLASSES_ICOMPARABLE_H
|
||||
#define CLASSES_ICOMPARABLE_H
|
||||
|
||||
class IComparable {
|
||||
public:
|
||||
virtual int CompareTo(IComparable* other) = 0;
|
||||
};
|
||||
|
||||
#endif //CLASSES_ICOMPARABLE_H
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "ClassA.h"
|
||||
|
||||
int main() {
|
||||
ClassA a;
|
||||
a.Print();
|
||||
|
||||
ClassA* pA = nullptr;
|
||||
pA = new ClassA();
|
||||
pA->Print();
|
||||
// (*pA).Print(); // same as above, but more complex to write
|
||||
delete pA;
|
||||
pA = nullptr;
|
||||
|
||||
a.CompareTo(pA);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user