我需要从函数返回一个类对象数组。我从研究中了解到,最好的方法是使用指针,但考虑到我的程序设计以及需要从多个 CPP 文件中访问它,这是最好的方法吗?
主文件
#include <class.h>
#include <functions.h>
int main(){
Class Object[2][]; //define second dimension here?
some_function(); //should return / create the array with filled in elements.
int var = arr[2][3]; // want to be able to do something like this in main
}
函数.cpp
void some_function(){
// assign values
arr[2][3] = 1;
}