Added: C++ projects
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
||||
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 4.3)
|
||||
project(Forward_Declaration)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(Forward_Declaration main.cpp
|
||||
functions.h
|
||||
functions.cpp)
|
||||
@@ -0,0 +1,6 @@
|
||||
//
|
||||
// Created by David Hackbarth on 21.09.26.
|
||||
//
|
||||
#include "functions.h"
|
||||
|
||||
void functionE() {} // defined
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by David Hackbarth on 21.09.26.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef FORWARD_DECLARATION_FUNCTIONS_H
|
||||
#define FORWARD_DECLARATION_FUNCTIONS_H
|
||||
|
||||
void functionE(); // declared
|
||||
|
||||
// void functionF() {} // declared & defined, linker error when included multiple times
|
||||
|
||||
#endif //FORWARD_DECLARATION_FUNCTIONS_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "functions.h"
|
||||
|
||||
void functionB() {} // declared & defined
|
||||
void functionC(); // declared
|
||||
void functionD(); // declared
|
||||
|
||||
int main()
|
||||
{
|
||||
// functionA(); // compiler error, because functionA is declared & defined after it is called
|
||||
functionB(); // no error
|
||||
// functionC(); // linker error, because functionC is declared but not defined
|
||||
functionD(); // no error
|
||||
functionE(); // no error
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void functionA() {} // declared & defined
|
||||
|
||||
void functionD() {} // defined
|
||||
|
||||
// void functionE() {} // linker error, because functionE is defined multiple times
|
||||
Reference in New Issue
Block a user