arrow operator c 2b 2b

Solutions on MaxInterview for arrow operator c 2b 2b by the best coders in the world

showing results for - "arrow operator c 2b 2b"
Emery
19 Jun 2017
1/* 
2 the arrow operator is used for accessing members (fields or methods)
3 of a class or struct
4 
5 it dereferences the type, and then performs an element selection (dot) operation
6*/
7
8#include <iostream>
9using std::cout;
10
11class Entity {
12public:
13	const char* name = nullptr;
14private:
15	int x, y;
16public:
17	Entity(int x, int y, const char* name)
18		: x(x), y(y), name(name) {
19		printEntityPosition(this); // "this" just means a pointer to the current Entity
20	}
21
22	int getX() { return x; }
23	int getY() { return y; }
24
25	friend void printEntityPosition(Entity* e);
26
27};
28
29// accessing methods using arrow
30void printEntityPosition(Entity* e) {
31	cout << "Position: " << e->getX() << ", " << e->getY() << "\n";
32}
33
34int main() {
35	/* ----- ARROW ----- */
36
37	Entity* pointer = new Entity(1, 1, "Fred");
38	//printEntityPosition(pointer); redacted for redundancy (say that 5 times fast)
39	
40  	cout << (*pointer).name << "\n"; // behind the scenes
41	cout << pointer->name << "\n"; // print the name (with an arrow)
42
43	/* ----- NOT ARROW ----- */
44
45	Entity not_a_pointer(2, 2, "Derf");
46	//printEntityPosition(&not_a_pointer); & to convert to pointer
47
48	cout << not_a_pointer.name << "\n"; // print the name (with a dot)
49
50	/* ----- LITERALLY NEITHER ----- */
51
52	std::cin.get(); // wait for input
53	return 0; // exit program
54}
55
56
queries leading to this page
implement dereference operator and arrow operator c 2b 2bc 2b 2b 3e operationwhat does the 3e does in c 2b 2bc 2b 2b arrow operator in classarrow functions c 2b 2bhow to code a arrow in c 2b 2bcpp when should i use arrowwhat is the member access operator arrow in c 2b 2b dot vs 3e in c 2b 2barrow function c 2b 2breferencer arrow in c 2b 2bc 2b 2b arrow function 3e operator in c 2b 2bdot vs arrow cppwhat is 3e operator in c 2b 2bwhat does the arrow mean in c 2b 2bc 2b 2b this arrowwhat 3e sign dipicts in pointer in cpparrow operator in class c 2b 2bthis 3e notation c 2b 2barrow operator in cpp classc 2b 2b vs arrowc 2b 2b arrow operator access field of pointerthis and arrow operatordot vs arrow c 2b 2bdot vs arrow in cpp 3e vs in c 2b 2bc 2b 2b arrow operator return 3e versus c 2b 2bwhen do we use the arrow operator in c 2b 2b pointersarrow syntax in c 2b 2barrow operator c 2b 2b classarrow function cppc 2b 2b arrow operator classarrow vs equal operator in c 2b 2bwhat si 3e c 2b 2bequal vs arrow in c 2b 2bcan arrow operator access variablesarrow operatro c 2b 2bc 2b 2b arrow operatorcpp arrowc 2b 2b arrow operator get field of pointer valuewhat is the arrow operator called c 2b 2barrow operator in cppc 2b 2b arrow equivalentarrow using symbol in c 2b 2b 3e cppwhat does the 3e operator do in c 2b 2barrows in c 2b 2bdot and arroe c 2b 2b 3e c 2b 2bdot and arrow operator in c 2b 2barrow function in c 2b 2barrow syntax with reference c 2b 2bstructure pointer c 2b 2b oepratorwhat does arrow mean in c 2b 2barrow operator in c 2b 2barrow sign in c 2b 2bwhen we use arrow and point in cppwhy do we use arrow with this 22this 3e 22 in c 2b 2b classesc 2b 2b arrow notationdot membership operatorc 2b 2b what does 3e meanc 2b 2b vs 3earrows in cppwhen is arrow used in cppaccess with arrow in c 2b 2bwhen to use and when 3e in c 2b 2b 3e in c 2b 2barrows c 2b 2bc 2b 2b arrowsc 2b 2b 3earrow notation c 2b 2barrow operator in c 2b 2barrow functions in c 2b 2b 3e operator cpp 3e operator c 2b 2bwhat is the arrow operator called 3f c 2b 2barrow in cppwhat do arrows do in c 2b 2bcpp arrow operator after function 2a vs 3e in c 2b 2b pointers 3esign in c 2b 2barrow operator c 2b 2binline arrow function c 2b 2bwhat does the right arrow mean in c 2b 2barrow or dot c 2b 2bc 2b 2b 5b 5d 28 29 3ealternative to arrow operator in cpparrow operator c 2b 2b no arguments 3e in cppc 2b 2b 3e nad pointarrow syntax c 2b 2bthis and arrow in class cppc 2b 2b dot vs arrowarrow operator c 2b 2b