Forward Declarations And Compiling Multiple Files Flashcards
Forward declaration
Tells the compiler about existence of identifier before defining an identifier
Function prototype
Declaration statement used to write a forward declaration, consists of function, return type, name, parameters, no body and (;)
Definition
Implements/instentiates the identifier
ODR
One definition rule
- within a file, function, objec or template
- within a program, an object or normal function
- types, templates and inline functions can have identical deffinitions in different files
Declaration
We use it when we want to use identifier before it is defined
Definitions
Are declarations in c++
Compiling files
Each file individualy, its limited visability and short memory is to have functions or variables that have same name without conflicting
To add new file
Right click source files in solution explorer and choose add, new file
Errors when working with multiple files
- forgeting to forward declaration to functions
- add.cpp is not added correctly
- add.cpp is added to wrong project
- file is set to not compile or link
- do not #include add.cpp from main.cpp
Naming collision
Error when 2 identical identifiers are introduced into the same program in a way where the compiler/linker can’t tell them apart
Occurence of naming collisions
- when 2 or more deffinitions for functions are introduced into a seperate files that are compiled into the same program
- when 2 or more definitions for functions are introduced into the same file
Namespace
Region that allows you to declare names inside of it for the purpose of disambiguation, provides own namespace scope and must have unique names.
Global namespace
Any name that is not defined inside a class, function or namespace
:: (symbol)
Scope resolution operator, identifier to the left identifies the namespace where the name to the right is contained with