Reputation: 1644
Embarrassingly basic question here... I have a Boost multidimensional array that I'm passing to a Class. I'd like the Class to be able to access the array via the pointer in its member functions. How do I do this?
class MyClass { public: MyClass( boost::multi_array & ); / private: boost::multi_array& arrPtr; void doSomethingInvolvingArray(); } MyClass::MyClass( boost::multi_array & arr ) { arrPtr = arr; // get "uninitialized reference member MyClass::arrPtr" here } void MyClass::doSomethingInvolvingArray( ) { int i = arrPtr[0][0][1]; // I want to do something like this }
Upvotes: 1
Views: 647
Reputation: 37938
Use an initializer list in the constructor:
MyClass::MyClass( boost::multi_array & arr ) : arrPtr(arr) {}
Just note you are using a reference in your code, not a pointer as you describe in your question.
Upvotes: 1