DS Log
In my blog, I delve into the world of programming web technologies, Linux, Unix-like, and graphic design using free tools on Linux.
KINGCODE
KingCode Editor (ex Texty Editor) is my project developed using Java Swing. Project is still in development and in beta version. I plan to add additional features focused for PYTHON, PHP, JAVA, C, JS and BASH.
Read more ↗
VUE on Linux
In this guide, I'll walk you through the step-by-step process of setting up Vue.js on your Linux system, empowering you to create dynamic and interactive web applications. Let's harness the power of Vue.js together on the Linux platform!
Read more ↗
Symfony PHP
Dive into the world of Symfony PHP with this comprehensive introduction. In this guide, you'll learn the essential steps to create and manage posts and users, empowering you to build dynamic web applications with ease.
Read more ↗
Trying Linux from Windows
How to set up a PHP development server on Ubuntu 22.04
Text editors
List of text editors for developers.
Read more ↗
Fonts
Important fonts everyone needs to know.
Read more ↗
Try Linux from Windows
Here are some quick videos I made showing how to try out Linux Mint on Windows.
Read more ↗
Saturday, December 27, 2025
C++ intro on Ubuntu Linux
Self-explanatory C++ intro on Ubuntu Linux.
Install compiler and editor
sudo apt update
sudo apt install build-essential geany geany-plugins
Basic
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
Store this in "basic.cpp" and compile it with:
g++ -std=c++17 -O2 -Wall -Wextra -o app basic.cpp
./app
Class basics
##include <iostream>
#include <string>
class Class2 {
public:
// Constructor
Class2(const std::string& message) : message(message) {}
// Method in Class2
void displayMessage() const {
std::cout << "Message from Class2: " << message << std::endl;
}
private:
std::string message;
};
class Class1 {
public:
// Constructor
Class1(Class2* class2Ptr) : class2Ptr(class2Ptr) {}
// Method in Class1 that calls a method in Class2
void callClass2Method() const {
if (class2Ptr) {
class2Ptr->displayMessage();
} else {
std::cout << "Class2 pointer is null" << std::endl;
}
}
std::string privateString;
private:
Class2* class2Ptr;
std::string hello;
};
int main() {
// Create an object of Class2
Class2 class2("Hello from Class2");
// Create an object of Class1, passing the Class2 object
Class1 class1(&class2);
// Call the method in Class1 that in turn calls a method in Class2
class1.callClass2Method();
return 0;
}
Constructor
//app.h
#ifndef APP_H
#define APP_H
#include <string>
class MyClass;
class MyClassTwo;
class App {
private:
int myPrivateProperty;
MyClass *myClass;
MyClassTwo *myClassTwo;
std::string appName;
public:
App(); // DECLARATION only - no implementation here!
void show();
void initMyClass(MyClass *myClass);
};
#endif
//app.cpp
#include "app.h"
#include "myclass.h"
#include "myclasstwo.h"
#include <iostream>
// IMPLEMENTATION goes here in the .cpp file
App::App() : myClass(nullptr), myClassTwo(nullptr) {
myPrivateProperty = 0;
appName = "MyApp";
std::cout << "hello world" << std::endl;
}
void App::show() {
std::cout << "Hello from App!" << std::endl;
}
void App::initMyClass(MyClass *myClass) {
this->myClass = myClass;
}
Extend class
#include <iostream>
#include <string>
// Base class
class Animal {
public:
std::string name;
Animal(std::string name) : name(name) {}
void speak() {
std::cout << name << " makes a sound." << std::endl;
}
};
// Derived class
class Dog : public Animal { //EXTENDS
public:
Dog(std::string name) : Animal(name) {}
void speak() override {
std::cout << name << " barks." << std::endl;
}
};
int main() {
Animal genericAnimal("Generic Animal");
genericAnimal.speak();
Dog myDog("Buddy");
myDog.speak();
return 0;
}
Header
//==== Animal.h ====/
#ifndef ANIMAL_H
#define ANIMAL_H
#include <string>
class Animal {
public:
std::string name;
Animal(std::string name);
virtual void speak();
};
#endif // ANIMAL_H
//==== Animal.cpp ====/
#include "Animal.h"
#include <iostream>
Animal::Animal(std::string name) : name(name) {}
void Animal::speak() {
std::cout << name << " makes a sound." << std::endl;
}
//==== Dog.h ====/
#ifndef DOG_H
#define DOG_H
#include "Animal.h"
class Dog : public Animal {
public:
Dog(std::string name);
void speak() override;
};
#endif // DOG_H
//==== Dog.cpp ====/
#include "Dog.h"
#include <iostream>
Dog::Dog(std::string name) : Animal(name) {}
void Dog::speak() {
std::cout << name << " barks." << std::endl;
}
//==== main.cpp ====/
#include "Animal.h"
#include "Dog.h"
int main() {
Animal genericAnimal("Generic Animal");
genericAnimal.speak();
Dog myDog("Buddy");
myDog.speak();
return 0;
}
This
#include <iostream>
#include <string>
class Person {
public:
std::string name;
Person(std::string name) : name(name) {}
void setName(std::string name) {
this->name = name; // 'this' is used to distinguish between the parameter and the member variable
}
void printName() const {
std::cout << "Name: " << this->name << std::endl;
}
};
int main() {
Person person("Alice");
person.printName();
person.setName("Bob");
person.printName();
return 0;
}}
Passing the Current Object as a Parameter
#include <iostream>
#include <string>
class Person {
public:
std::string name;
Person(std::string name) : name(name) {}
void printName() const {
std::cout << "Name: " << name << std::endl;
}
void updateName(const Person& other) {
this->name = other.name; // 'this' is used to access the current object's member
}
};
int main() {
Person person1("Alice");
Person person2("Bob");
person1.printName();
person2.printName();
person1.updateName(person2);
person1.printName();
return 0;
}
Returning the Current Object from a Member Function
#include <iostream>
#include <string>
class Person {
public:
std::string name;
Person(std::string name) : name(name) {}
Person& setName(std::string name) {
this->name = name; // 'this' is used to access the current object's member
return *this; // Return the current object
}
void printName() const {
std::cout << "Name: " << name << std::endl;
}
};
int main() {
Person person("Alice");
person.printName();
person.setName("Bob").setName("Charlie"); // Chaining method calls
person.printName();
return 0;
}
Handle list of functions
#include <vector>
#include <iostream>
int add1(int x){ return x+1; }
int mul2(int x){ return x*2; }
int main(){
std::vector<int(*)(int)> funcs;
funcs.push_back(add1);
funcs.push_back(mul2);
int v = 3;
for (auto f : funcs) {
int output = f(v);
std::cout << output << std::endl;
}
}
Project structure
- 🗎 build.sh
- 📁 classes
-
- 🗎 app.cpp
- 🗎 app.h
- 🗎 myclass.cpp
- 🗎 myclass.h
- 🗎 main.cpp
- 📁 resources
- 📁 vendor