kchyn 0 Newbie Poster 13 Years Ago is it possible to pass this to a function? it's size is configured at runtime. for example, void test(string s[][]) { return; } int main() { int x, y; cin >> x >> y; string s[x][y]; test(s); return 0; } c++ 0 0 Reply with Quote Share mrnutty 761 Senior Poster 13 Years Ago Yes, but if you want to do it that way, you need to do manual allocation. void foo(string** strs, int width, int height){ //... } int main(){ int width = 0, height = 0; cin >> height >> width; string **strs = new string*[height]; for(int i = 0; i < height; ++i){ strs[i] = new string[width]; } foo(strs, width, height); } You might want to skip doing manual memory management and possible use std::vectors typedef std::vector<string> StringArray; void foo(std::vector<StringArray>& arrayList){ //... } int main(){ int height = 0, width = 0; cin >> height >> width; std::vector<StringArray> myList(height , StringArray(width) ); foo(myList); } 1 0 Reply with Quote Share Share Facebook Twitter LinkedIn Reply to this topic Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge. Sign Up — It's Free!
mrnutty 761 Senior Poster 13 Years Ago Yes, but if you want to do it that way, you need to do manual allocation. void foo(string** strs, int width, int height){ //... } int main(){ int width = 0, height = 0; cin >> height >> width; string **strs = new string*[height]; for(int i = 0; i < height; ++i){ strs[i] = new string[width]; } foo(strs, width, height); } You might want to skip doing manual memory management and possible use std::vectors typedef std::vector<string> StringArray; void foo(std::vector<StringArray>& arrayList){ //... } int main(){ int height = 0, width = 0; cin >> height >> width; std::vector<StringArray> myList(height , StringArray(width) ); foo(myList); } 1 0 Reply with Quote Share