C++ An Introduction

C++ IS Compiled Object-oriented Cross-platform Fast

FILES Header

Source

.h extension

.cpp extension

Defines a class’ interface

Defines a class’ implementation

INTERFACE Describes what a class is. What does it inherit from? What are its public methods? What are its public data members?

#ifndef __GameOfLife__Grid__ #define __GameOfLife__Grid__

header guard

#include "cocos2d.h" #include "Creature.h" class Grid : public cocos2d::Node { public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount();

class definition

protected: int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

protected member

};

void setupGrid(); void setupTouchHandling(); void updateNeighborCount(); void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

#endif /* defined(__GameOfLife__Grid__) */

public member

functions variables protected member

functions

#ifndef __GameOfLife__Grid__ #define __GameOfLife__Grid__

header guard

#include "cocos2d.h" #include "Creature.h" class Grid : public cocos2d::Node { public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount(); protected: int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

};

Place all header code between header guards

Header guards prevent the same header from being included twice

void setupGrid(); void setupTouchHandling(); void updateNeighborCount(); void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

#endif /* defined(__GameOfLife__Grid__) */

#ifndef __GameOfLife__Grid__ #define __GameOfLife__Grid__ #include "cocos2d.h" #include "Creature.h"

class definition

class Grid : public cocos2d::Node { public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount();

protected: int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

};

Defines class name

Defines what the class inherits from

void setupGrid(); void setupTouchHandling(); void updateNeighborCount(); void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

#endif /* defined(__GameOfLife__Grid__) */

#ifndef __GameOfLife__Grid__ #define __GameOfLife__Grid__ #include "cocos2d.h" #include "Creature.h" class Grid : public cocos2d::Node {

public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount(); protected: int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

};

public member

functions

These are the functions that can be called by other classes to interact with this class

void setupGrid(); void setupTouchHandling(); void updateNeighborCount(); void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

#ifndef __GameOfLife__Grid__ #define __GameOfLife__Grid__ #include "cocos2d.h" #include "Creature.h" class Grid : public cocos2d::Node { public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount();

These variables are only accessible by this class and subclasses Other classes can not access them

protected: int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

};

void setupGrid(); void setupTouchHandling(); void updateNeighborCount(); void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

protected member

variables

#define __GameOfLife__Grid__ #include "cocos2d.h" #include "Creature.h" class Grid : public cocos2d::Node { public: CREATE_FUNC(Grid); bool init() override; void onEnter() override; void evolveStep(); int getGenerationCount(); int getPopulationCount();

protected:

These functions are only accessible by this class and subclasses Other classes can not access them

int generationCount; int populationCount; float cellWidth; float cellHeight; cocos2d::Vector gridArray;

};

void setupGrid(); protected member void setupTouchHandling(); void updateNeighborCount(); functions void updateCreatures(); Creature* creatureForTouchLocation(cocos2d::Vec2 touchLocation); bool isValidIndex(int row, int col); int indexForRowColumn(int row, int col);

public Any class can call these functions or access these variables

protected Only this class and subclasses can call these functions or access these variables

private Only this class can call these functions or access these variables

IMPLEMENTATION Describes how the class works. Contains implementations of member functions Sets default values for member variables

#include "Grid.h" using namespace cocos2d; bool Grid::init() { if (! Node::init()) { return false; } generationCount = 0; populationCount = 0; return true; } void Grid::onEnter() { Node::onEnter(); this->setupGrid(); this->setupTouchHandling(); }

member function definitions

#include "Grid.h"

#include header

using namespace cocos2d; bool Grid::init() { if (! Node::init()) { return false; } generationCount = 0; populationCount = 0; return true; } void Grid::onEnter() { Node::onEnter(); this->setupGrid(); this->setupTouchHandling(); }

Must include own class header file Ex. Grid.cpp must include Grid.h

#include "Grid.h"

using namespace cocos2d; bool Grid::init() { if (! Node::init()) { return false; }

namespace declarations

Any using namepace declarations go here

generationCount = 0; populationCount = 0; return true; } void Grid::onEnter() { Node::onEnter(); this->setupGrid(); this->setupTouchHandling(); }

Do not put using namespace declarations in header files

#include "Grid.h" using namespace cocos2d; bool Grid::init() { if (! Node::init()) { return false; }

Implementations for public, private and protected functions declared in header

generationCount = 0; populationCount = 0; return true; } void Grid::onEnter() { Node::onEnter(); this->setupGrid(); this->setupTouchHandling(); }

member function definitions

C++ FUNCTION bool Grid::isValidIndex(int row, int col)

class scope return type

function name

parameters

C++ TYPES bool char float double int

bits

range

example

8

true, false

true, false

8

-127 to 127 0 to 255

54, ‘h’

32

+/- 3.4e +/- 38 ~7 digit precision

5.326f

64

+/- 1.7e +/- 308 ~15 digit precision

27.495

32

-2,147,483,648 to 2,147,483,647

34

INHERITANCE

void retain()

Ref

void release() unsigned int _referenceCount

… void setPosition(float x, float y)

Node

Vec2 getAnchorPoint(); void addChild(Node* child);

… …

Sprite

void setTexture(std::string filename);

ENCAPSULATION

generationCount and populationCount

are properties of Grid class Grid : public cocos2d::Node { public: int generationCount; int populationCount; };

Why is this bad?

class Grid : public cocos2d::Node { public: int getGenerationCount(); void setGenerationCount(int generationCount)

This is good because the implementation of generationCount and populationCount are hidden from other classes.

int getPopulationCount(); void setPopulationCount(int populationCount) protected: int generationCount; int populationCount; };

The value of generationCount and populationCount cannot be changed without Grid knowing about it.

C++ IS - GitHub

#ifndef __GameOfLife__Grid__. #define __GameOfLife__Grid__. #include "cocos2d.h". #include "Creature.h" class Grid : public cocos2d::Node. { public:.

264KB Sizes 2 Downloads 338 Views

Recommend Documents

() c - GitHub
(SAP Class Room and Online Training Institute). #514,Annapurna Block,. Adithya Enclave,Ameerpet. Ph:8464048960,www.sysarch.in. BW-81-BO I BI-ABAP I 80 ...

C++98 features? - GitHub
Software Architect at Intel's Open Source Technology. Center (OTC). • Maintainer of two modules in ... Apple Clang: 4.0. Official: 3.0. 12.0. 2008. C++11 support.

C-SHARP - GitHub
email address, and business phone number would be most appreciated) c) Method used ... best reflects the population under study. For convenience, the mean ...

What is NetBeans? - GitHub
A comprehensive, modular IDE. – Ready to use out of the box. – Support for latest Java specifications. & standards. – Other languages too. (PHP, C/C++, etc). – Intuitive workflow. – Debugger, Profiler,. Refactoring, etc. – Binaries & ZIPs

What is Hibernate Search? - GitHub
2015 - MARTIN BRAUN - APPLIED COMPUTER SCIENCE IV, UNIVERSITY OF BAYREUTH. 1. Introduction. Hibernate Search with Hibernate ORM: Database.

C++1* Tech Talks - GitHub
6 std::string p_sa = new std::string[5];. // -> elements are default initialized ... S s6. {1, {2, 3, {4, 5, 6, 7 } } }; // compile-time error, ill-formed. 18 int ai[] = {1, 2.0 }; .... be careful with the empty brace initializer (PODs/aggregates vs

Coroutines in C++17 - GitHub
http://isocpp.org/files/papers/N4403.pdf ... to a function call overhead) ... coroutines call. Allocate frame, pass parameters. Allocate frame, pass parameters return.

C# Anleitung - REST + Klienten - GitHub
"Data Source=(localdb)\\v11.0;Initial Catalog=MusicDb;Integrated Security=True" .... Name = "Gordon Goodwin Big Phat Band",. Songs = new List().

BDE C++ Coding Standards - GitHub
Nov 7, 2012 - that the above illustration is not shown with the correct number of columns, due to .... storage specifier, however, has an ancillary benefit of making ...... Classes that meet these basic criteria are said to be const thread-safe.

What is structured prediction? - GitHub
9. Hal Daumé III ([email protected]). State of the art accuracy in.... ➢ Part of speech tagging (1 million words). ➢ wc: ... iPython Notebook for Learning to Search.

BDE C++ Coding Standards - GitHub
Jul 7, 2015 - that the above illustration is not shown with the correct number of ...... See Rule 12.3.1 for the details of creating sub-headings. ...... Page 50 ...

122COM: Introduction to C++ - GitHub
All students are expected to learn some C++. .... Going to be learning C++ (approved. ). ..... Computer Science - C++ provides direct memory access, allowing.

What Is AWS Icebreaker? - GitHub
physical devices from smart phone apps. The following diagram illustrates a high-level view of the Icebreaker service: You can interact with Icebreaker in a ...

Test-driven development in C++ - GitHub
Richard Thomson. Senior Software Engineer. Fusion-io. @LegalizeAdulthd http://LegalizeAdulthood.wordpress.com [email protected] ...

BP-6811 C BP-6811 C BP-6811 C BP-6811 D BP-6811 D - GitHub
BP-6811. 05-05-B. BP-6811. C. BP-6811. 05-05-B. BP-6811. C. BP-6811. 05-05-B. BP-6811. C. BP-6811. 05-05-A. BP-6811. D. 811. -A. BP-6811. D.

Interactive test tool for interoperable C-ITS development - GitHub
School of Information Technology. Halmstad University, Box 823, 30118, ... tween physical wireless networking and virtual ITT networking. Therefore, only one ...

Variant A Variant B Variant C Variant D - GitHub
2017-05-15 13:15 /home/wingel/eagle/diff-probe/diff-probe.sch (Sheet: 1/1). Variant A. Variant B. Variant C. Variant D. LMH6702. 0. Ω. /N. F. NF. 1. 5. 0. Ω. GND. GND. 2. 2. 0. Ω. N. F. CON-1X3-TAB-AMP-29173-3-NARROW. V. +. V. -. GND. V. +. V. -.

International Marketing by Philip R. Cateora, Mary C ... - GitHub Pages
The benefit you get by reading this book is actually information inside this reserve incredible fresh ... you can have it inside your lovely laptop even cell phone.

A review of C++ 11/14 only Boost libraries - GitHub
1. 1. 1. Boost.Hana. Louis Dionne. 14 none. 2015-04. 1. 0.9. 0.6 header only. 1. 1 ... standalone ASIO the Networking TS reference impl ..... service design and .

TEB + 0x800 is Win32ClientInfo structure Offset 0x20 used to ... - GitHub
... is gone, it is possible to just search the pure data looking for an object handle ... the user mode mapping to the base of the kernel desktop heap to gain the true.

NOTE: PCB Revision for this board is Rev B6 - GitHub
Description. DATE. GC. 11/19/2012. Initial production Release. A4A. A5. On the initial production release the processors were to be found incorrect as supplied by TI. ... There is a small chance that on power up the nRESETOUT signal on the processor

FAKULT¨AT F¨UR INFORMATIK Adding C++ Support to ... - GitHub
Sep 16, 2013 - of the language are taken into account in an attempt to build a better C++ language flavor. Several analyses are ... 3.1.10 OtherMPSInstruments . ..... In this work we describe a C++ programming language implementation6 on top of mbedd

Threads and Shared Variables in C++0x - GitHub
May 19, 2011 - Performance consequences. – and how ... In C++0x, destroying a joinable thread calls terminate()! ..... Java: volatile, java.util.concurrent.atomic.