User Tools

Site Tools


Sidebar

Dan's Wiki

DokuWiki Instructions (local) DokuWiki Manual
Site Checker (Orphans Wanted)

Edit Sidebar

programming:cplusplus:start

This is an old revision of the document!


C++ Notes and Information

Helpful tutorials on YouTube are by TheChernoProject https://www.youtube.com/channel/UCQ-W1KE9EYfdxhL6S4twUNw

Memory

There are two areas of memory, Stack, and Heap.

StackWhen scope for variable ends, the memory is freed.
HeapStays there until manually removed with delete

new keyword

The new keyword allocates memory from the Heap. It returns a pointer to it. The number of bytes to allocated is determined by the argument. int provides 4 bytes, for example.

int * a = new int;
 
*a = 2;
 
std::cout << *a << std::endl;
int * a = new int;
// is nearly identical to this:
int * a = malloc(4);

Visual Studio Formatting/Indenting C++ code

Use Control-K, followed by Control-F. 7/5/2019

Separate Classes into Headers and CPP files

C++ classes (and often function prototypes) are normally split up into two files. The header file has the extension of .h and contains class definitions and functions. The implementation of the class goes into the .cpp file. By doing this, if your class implementation doesn’t change then it won’t need to be recompiled….

separatecompilation.pdf

Difference between Dot and Arrow

Use Arrow when the value on the left is a pointer, use a dot when it is a class instance.

To access members of a structure, use the dot operator. To access members of a structure through a pointer, use the arrow operator. Details

programming/cplusplus/start.1571516041.txt.gz · Last modified: 2019/10/19 20:14 by dwheele