1 Intro C++ Flashcards
Main()
- not part of any class, is a function NOT a method because of this
- must be global
- return type int, return 0 always
include
Compiler inserts the contents of the file “something” in the place where the #include statement appears
Functions vs methods
functions are outside of a class
Forward declarations
declaring a function before you implement it, so you can use it in earlier functions/methods
Syntax for making a class?
class className {};
**note ; after class declaration
Syntax for making a constructor?
className::className() { //create variablels n stuff }
** notice NO return type
Where do you define a class? Implement aa class?
- Header file!
2. .cpp file
What should a header file contain?
- Appropriate preprocessor directives
- class declaration
- public and private methods declaration
What should a class’s .cpp file contain?
- # include it’s header file
- initialize all methods of the class
Straight up meaning of
#include #ifndef #endif #define
#include = direct copy of file specified to location of this #ifndef = "if not defined" #endif = the end of any preprocessing ifs #define = defines a macro... can make #define HOP 5
What should you #include?
.h files
#define FOO #ifdef FOO // is true! // ... #endif #ifndef FOO // is false! // ... #endif
Understand!
include loops
never ending inclusion of two files
odd.h: #ifndef ODD_H #define ODD_H #include "even.h" bool odd (int x); #endif even.h: #ifndef EVEN_H #define EVEN_H #include "odd.h" bool even (int x); #endif
odd.h: #ifndef ODD_H 1 #define ODD_H 2 #include "even.h" 3 bool odd (int x); 9 #endif 10
even.h: #ifndef EVEN_H 4 #define EVEN_H 5 #include "odd.h" 6 (already defined so nothing occurs) bool even (int x); 7 #endif 8
Whats a pointer?
a type of variable which stores a memory address of another object… instead of a number or a character
How to make a pointer?
int x;
chary;
poopy *poopyhead;