Tải bản đầy đủ (.pptx) (236 trang)

GettingStartedCpp - full pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (12.29 MB, 236 trang )

G
e
t
t
i
n
g

S
t
a
r
t
e
d

C
/
C
+
+
N
g
u
y
e
n

K
h
a


n
h

D
u
y
S
a
i
-
D
e
v

T
r
a
i
n
i
n
g

t
e
a
m
Preparation
Getting Start
OOP

Memory management
Rest of C/C++ features
Appendix
Outline
C/C++
2
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Appendix
Hello world
C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
3
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Appendix
Variables and constant
Primary data type
Array – Pointer – String
Data structure: enum – union - struct
Function

Namespace
Outline
4
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Appendix
Class & Object
Inheritance
Polymorphism
Operator overloading
Class’ static member
Outline
5
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Appendix
Recall pointer
Memory leak
Outline
6
Preparation
Getting Start
OOP
Memory management

Rest of C/C++ features
Appendix
Forward declaration
Standard IO – Console IO & FILE
Template
Type casting
Exception handling
Endian
STL introduction
GNU GCC/G++
Outline
7
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Hello world!
C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
8
Preparation
Getting Start
Basic Data Structure
OOP
Memory management
Rest of C/C++ features

Hello world!
C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
9
Hello world using VS
Step 1: create new project
Step 1: create new project (cont)
Step 2: add new file
Step 2.1: add cpp file
10
Hello world
# include <stdio.h>
void main()
{
printf("Hello world");
}
main.cpp
Use standard IO lib
Entry point
Print to console screen
11
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Hello world!

C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
12
C/C++ source files
Header file (.h)

aka include file

Hold declarations for other files use (prototype)

Not required
#include "stdio.h"
void Todo1();
void Todo2();
# include "header.h"
void Todo1()
{
Todo2();
}
void Todo2(){}
void main()
{
Todo1();
}
.h file
.cpp file
Source file (.c / .cpp)


Content implementation

Required
13
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Hello world!
C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
14
Entry point

Required unique entry point

The most common is: main
void main()
{
// your code here
}
Form1.cpp
int main(int n, char ** args)
{
// your code here

}
Form2.cpp
1>LINK : fatal error LNK1561: entry point
must be defined
Error when no entry point is defined
15
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Hello world!
C/C++ files
Entry point
C/C++ libraries
Source compile process
Outline
16
C/C++ standard library

C/C++ support a set of internal basic
library, such as

Basic IO

Math

Memory handle




For using, include the header file
#include <…>
#include "…"
#include "stdio.h"
void main()
{
printf("hello");
}
17
C header C++ header
<assert.h> <cassert>
Content assert macro, for debugging
<Ctype.h> <cctype>
For character classification/convert functions
<Errno.h> <cerrno>
For testing error number
<float.h> <cfloat>
Floating point macros
<limits.h> <climits>
Define range of value of common type
<math.h> <cmath>
Mathematical functions
<setjmp.h> <csetjmp>
Provide “non-local jumps” for flow control
<signal.h> <csignal>
Controlling various exceptional conditions
<stdlib.h> <cstdlib>
Standard lib
<stddef.h> <cstddef>

<stdarg.h> <cstdarg>
<stdio.h> <cstdio>
Standard IO
<string.h> <cstring>
Manipulating several kinds of string
<time.h> <ctime>
Converting between time & date formats
<wchar.h> <cwchar>
<wctype> <cwctype>
18
C/C++ user-defined lib

Not C/C++ standard lib

Come from:

Third-party

User own

In common, include 2 parts

.h files & .lib files: for developer

.dll file (dynamic library): for end-user
error LNK2019: unresolved external symbol
Error caused when forget to add .lib file
19
C/C++ user-defined lib (cont.)


For using

Include .h files

Inform .lib files to compiler

Copy all .dll file to (if any) :
o
same folder with execute file, or
o
to system32 (windows) – not recommend
20
Declare path to .lib
Import user-defined library
Visual studio
21
Import user-defined library
Visual studio
Declare .lib file
22
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
C/C++ files
Entry point
C/C++ libraries
Hello world!
Source compile process

Outline
23
Source
.h/.c/.cpp
preprocess
Preprocessed
source
Compile
.o / .obj
(object file)
Linker
Executable/
lib
Process
Tools:

Visual Studio: cl.exe (Press F7 / F5)

GNU GCC: gcc/ g++
24
Preparation
Getting Start
OOP
Memory management
Rest of C/C++ features
Variables and constant
Primary data type
Array – Pointer - String
Data structure: enum – union - struct
Function

Namespace
Outline
25

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×