i have this class
struct A {
A();
Item* m_Items[ON_CPU + ON_GPU];
Item** m_ItemsOnCpu;
Item** m_ItemsOnGpu;
};
I need to initialize
m_ItemsOnCpu to m_Items
and
m_ItemsOnGpu to m_Items + ON_CPU
So I need const pointers to two parts of the array. How do I need to declare and then initialize them?
In C++11 you can just do:
struct A {
A();
Item* m_Items[ON_CPU + ON_GPU];
Item** const m_ItemsOnCpu = m_Items;
Item** const m_ItemsOnGpu = m_Items + ON_CPU;
};
On other versions of C++, use an initialization list:
struct A {
A() : m_ItemsOnCpu(m_Items), m_ItemsOnGpu(m_Items + ON_CPU) {};
Item* m_Items[ON_CPU + ON_GPU];
Item** const m_ItemsOnCpu;
Item** const m_ItemsOnGpu;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With