"c++ smart pointer 2d array" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ smart pointer 2d array" answered properly. Developers are finding an appropriate answer about c++ smart pointer 2d array related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ smart pointer 2d array. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ smart pointer 2d array.
c++ smart pointer 2d array
#include <iostream>
#include <memory>
using namespace std;
int main(){
//this just builds a 2D array pi that looks like
//0 1 2 3 4
//5 6 7 8 9
//10 11 12 13
//... 24
int** pi=new int*[5];
//this counter is augmented by 5 in every loop,
//for the value to be 0...,5,..10etc
int counter=0;
for(int j=0;j<5;j++){
int* i=new int[5];
for(int j=0;j<5;j++)
i[j]=j+counter;
counter=counter+5;
pi[j]=i;
//just to print out the array
for(int k=0;k<5;k++)
cout<<pi[j][k]<<" ";
cout<<endl;
}
cout<<endl;
//trying the same thing using smart pointers
unique_ptr<int*[]> smp_pi(new int*[5]);
counter=0;
for(int j=0;j<5;j++){
unique_ptr<int[]> smp_i(new int[5]);
for(int k=0;k<5;k++){
smp_i[k]=counter+k;
cout<<smp_i[k]<<" ";
}
counter=counter+5;
cout<<endl;
smp_pi[j]=&smp_i[0];
//smp_pi[j]=smp_i; //this does not compile. why?
}
cout<<endl;
for(int j=0;j<5;j++){
for(int k=0;k<5;k++)
cout<<smp_pi[j][k]<<" ";
cout<<endl;
}
return 0;
}
Source: www.cplusplus.com
All those coders who are working on the C++ based application and are stuck on c++ smart pointer 2d array can get a collection of related answers to their query. Programmers need to enter their query on c++ smart pointer 2d array related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ smart pointer 2d array for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ smart pointer 2d array while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ smart pointer 2d array". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ smart pointer 2d array resolved professionally and stay updated to the latest C++ updates.