35 minutes ago, matt77hias said:I don't know why Intellisense gets mad
Intellisesne might be the wrong word here. Its whichever entity is responsible putting a red squiggly under things. The linter?
30 minutes ago, alvaro said:
You don't need to inherit to share functionality. Composition will be better in the vast majority of situations. So both VertexBuffer and ConstantBuffer can have a member of type Buffer (or MemoryBuffer, or RawBuffer... Using good names is important) and share functionality that way.
I kind of lied here, completely forgot what I was trying to do. I actually do have a spot where I could use a vector of Buffers. I have this factory called BufferModule which has methods like createVertexBuffer, createIndexBuffer, etc. All of those buffer classes (VertexBuffer, IndexBuffer, etc) are derived from the base Buffer. So in order to hold all of these I need a member variable like
std::vector<Buffer*> bufferObjects;
Cause if I were to just a normal vector of objects, my child buffer class would be sliced when I would try to do something like this right?
//Vector of the parent class Buffer
std::vector<Buffer> bufferObjects;
//Put the child class VertexBuffer into the vector
VertexBuffer vertexBuffer;
graphicsDevice->device->CreateBuffer(&bufferDescription, NULL, &vertexBuffer.buffer);
buffers.push_back(vertexBuffer); // Not good... Just lost all of the info that was not specifically a part of the parent class
So to fix this I would need to do
//Vector of the parent class Buffer. Using a pointer to prevent the object slice
std::vector<Buffer*> bufferObjects;
VertexBuffer vertexBuffer = new VertexBuffer(); //Need to use new here otherwise when this goes out of scope all of our data goes bye-bye
graphicsDevice->device->CreateBuffer(&bufferDescription, NULL, &vertexBuffer.buffer);
buffers.push_back(&vertexBuffer); //Hurray! No object slicing happens
Only problem I have here is that I really don't like the use of the new keyword