example2_static_type_checking.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <iostream>

void printNumber(int num) {
    std::cout << "The number is: " << num << std::endl;
}

int main() {
    printNumber(42);  // OK
    
    // Uncommenting the next line will cause a compile-time error
    // printNumber("42");  // Error: cannot convert const char* to int
    
    return 0;
}
Back to type_safety