This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example declaration | |
// declaration of a class | |
class MyClass; | |
// delaration of a function | |
int my_function (int arg); | |
// declaration of varibales, also contains definition | |
int my_var; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example definition | |
// definition of a class | |
class MyClass { | |
private: | |
int m_size; | |
public: | |
MyClass(int n) : m_size(n){} | |
~MyClass() {} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool is_even(int n); | |
bool is_odd(int n); | |
bool is_even(int n) { | |
if (n == 0) | |
return true; | |
else | |
return is_odd(n - 1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example.cpp: In function ‘bool is_even(int)’: | |
example.cpp:8:16: error: ‘is_odd’ was not declared in this scope | |
return is_odd(n - 1); | |
^~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class House; | |
class Owner; | |
class House{ | |
public: | |
Owner* my_owner; | |
House(Owner* owner){ | |
my_owner = owner; | |
} | |
~House(){} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_example.cpp:6:5: error: ‘Owner’ does not name a type | |
Owner* my_owner; | |
^~~~~ | |
class_example.cpp:8:19: error: ‘Owner’ has not been declared | |
void setOwner(Owner* owner){ | |
^~~~~ | |
class_example.cpp: In member function ‘void House::setOwner(int*)’: | |
class_example.cpp:9:9: error: ‘my_owner’ was not declared in this scope | |
my_owner = owner; | |
^~~~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int a = 1; | |
int foo(){ | |
return a; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bar() { | |
return 1; | |
} | |
int foo(){ | |
return bar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "util.h" | |
int foo(){ | |
return bar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int foo(){ | |
// can't find bar's definition | |
return bar(); | |
} | |
int bar() { | |
return 1; | |
} |