Created
April 27, 2020 14:27
-
-
Save YuehChuan/ab7cdeb8cebf53f6afc9579cda1e924e to your computer and use it in GitHub Desktop.
(parameter with reference or pointer)g++ -std=c++11 main.cpp -o main
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
#include <iostream> | |
#include <memory> | |
void foo( const std::shared_ptr<int> p) | |
{ | |
static int x = 0; | |
*p = ++x; | |
// printf("address p %p \n",p); | |
// printf("value x %d \n",x ); | |
// printf("value p %d \n",*p); | |
} | |
int main() | |
{ | |
auto p = std::make_shared<int>(); | |
auto start = clock(); | |
for (int i = 0; i < 10; ++i) | |
{ | |
foo(p); | |
} | |
std::cout << "Took " << clock() - start << " ms" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment