example2_function_class_definitions.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

// Function definition
void printMessage() {
    std::cout << "Hello from a function!" << std::endl;
}

// Class definition
class MyClass {
public:
    MyClass() {
        std::cout << "Constructor called" << std::endl;
    }
    
    void memberFunction() {
        std::cout << "Member function called" << std::endl;
    }
};

int main() {
    printMessage();
    
    MyClass obj;
    obj.memberFunction();
    
    return 0;
}
Back to curly_brackets