S
S
s2sk13372017-11-06 04:16:06
C++ / C#
s2sk1337, 2017-11-06 04:16:06

Can't make a dynamic pointer?

Hello.
We need to make a two-dimensional dynamic array of ID3D11Buffer type pointers (DirectX 11 pointer to buffer).
I write like this:

ID3D11Buffer*** g_pVertexBuffer = new ID3D11Buffer**[];

To which the compiler reacts like this:
"Error C3078 array size must be specified in new expressions"
What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2017-11-06
@s2sk1337

Specify the size in square brackets

class ID3D11Buffer{};//объявим заглушку для примера

using PID3D11Buffer = ID3D11Buffer*;
using PPID3D11Buffer = PID3D11Buffer*;

int main()
{
    PPID3D11Buffer* g_pVertexBuffer = new PPID3D11Buffer[42];
}

But in general, with this approach, you will quickly get confused. Use std::vector for resizable arrays and std::array for immutable ones.
If you need to declare new sometype[count], then use en.cppreference.com/w/cpp/memory/unique_ptr/make_unique instead

S
Sergey Kormishin, 2017-11-06
@coremission

When you write like this:
The compiler asks you what size block of memory you need to allocate?!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question