Created
March 21, 2020 21:33
-
-
Save shaomeng/d3749e20588e76d3c406b916446652f2 to your computer and use it in GitHub Desktop.
pass by reference
This file contains hidden or 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> | |
| using buffer_type = std::unique_ptr<float[]>; | |
| template< typename T > | |
| void print_2nd_val( T ptr ) | |
| { | |
| std::cout << ptr[1] << std::endl; | |
| } | |
| template void print_2nd_val( const buffer_type& ); | |
| int main() | |
| { | |
| int N = 10; | |
| buffer_type buf = std::make_unique< float[] >( N ); | |
| for( int i = 0; i < N; i++ ) | |
| buf[i] = float(i); | |
| const buffer_type& ref = buf; | |
| print_2nd_val( ref ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment