Created
March 14, 2012 09:49
-
-
Save domenicomonaco/2035449 to your computer and use it in GitHub Desktop.
Tipo reference & Puntatori in CPP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : TestCPP.cpp | |
// Author : Domenico Monaco | |
// Version : | |
// License : GPLv2 | |
// Copyright : Domenico Monao 2012 - | |
// Description : Hello World in C++, Ansi-style | |
//============================================================================ | |
#include <iostream> | |
using namespace std; | |
int & first(int* a); | |
class Queue { | |
int items[100]; | |
int front, rear; | |
public: | |
Queue(){ | |
front = 1; | |
items[front] = 14; | |
items[2] = 7; | |
items[front] = 20; | |
} | |
int & first(Queue * q) { | |
//return q->items[front]; | |
return (*q).items[front]; | |
} | |
}; | |
int & first(int* a) { | |
//cout << "" << *a; | |
return *a; | |
} | |
int main() { | |
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! | |
int *q; | |
int b; | |
int i; | |
b = 3; | |
q = &b; | |
first(q)++; | |
i = first(q); | |
first(q) = 10; | |
cout << "" << i << endl; | |
cout << "" << (*q) << endl; | |
cout << "" << (b) << endl; | |
cout << "" << &b << endl; | |
cout << "" << &i << endl; | |
cout << "" << &q << endl; | |
cout << "###########" << endl; | |
Queue p; | |
int test = p.first(&p); | |
cout << "#0 " << test << endl; | |
p.first(&p)++; | |
cout << "#1 " << p.first(&p) << endl; | |
p.first(&p) = p.first(&p) + 1; | |
cout << "#2 " << p.first(&p) << endl; | |
//Non funziona | |
//p.first(&p)* = p.first(&p) + 1; | |
//cout << "#3 " << p.first(&p) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment