0

I am trying to set up a multi-typename method in an objects constructor to call from within a derived class, but I cannot figure out why I am getting the following error:

no instance of constructor "VBO::VBO" matches the argument list
argument types are: 
(VkGraphicsPipeline *, std::vector<Vertex, std::allocator<Vertex>>)

The VBO object is defined as follows:

struct VBO {
    VkBuffer buffer;
    VkDeviceMemory memory;
    VBO(VkGraphicsUnit* pVkGPU, std::vector<std::variant<Vertex, uint32_t>> content) {
        ...; }
};

The VkGraphicsPipeline object is defined as the child of a VkGraphicsUnit object:

struct VkGraphicsPipeline : VkGraphicsUnit {   
    VkGraphicsPipeline(VulkanAPI VkApplication, std::vector<Vertex> vertices) : VkGraphicsUnit(VkApplication) {
        VBO(this, vertices);
        ...; }
};

I have tried the following things, all of which have failed to fix the error:

Adding "public" before "VkGraphicsUnit"

struct VkGraphicsPipeline : public VkGraphicsUnit 

Adding VBO as a subclass of VkGraphicsPipeline

Removing the inheritance of VkGraphicsUnit and calling it explicitly

struct VkGraphicsPipeline {
    VkGraphicsPipeline(VkGraphicsUnit* pVkGPU, std::vector<Vertex> vertices) {
        VBO(pVkGPU, vertices);
        ...; }
};

And even trying out the other available variant in the VBO constructor

VkGraphicsPipeline(VkGraphicsUnit* pVkGPU, std::vector<uint32_t> indices) {
   VBO(pVkGPU, indices); }

In the last two cases, the error I was getting was,

no instance of constructor "VBO::VBO" matches the argument list
argument types are:
(VkGraphicsUnit *, std::vector<Vertex, std::allocator<Vertex>>)

and

no instance of constructor "VBO::VBO" matches the argument list
argument types are:
(VkGraphicsUnit *, std::vector<uint32_t, std::allocator<uint32_t>>)

I am completely lost for a solution. Please help me find out what I am missing and how/if I can get around this error without making my code any more complicated than it already is.

6
  • Additionally, I tried adding a "VBO vbo;" member to the VkGraphicsPipeline object and then calling "vbo = VBO(pVkGPU, vertices);" from within the VkGraphicsPipeline constructor to no avail. Jun 2 at 1:05
  • 3
    You're passing different types of vectors into VBO. It's expecting a vector of variants, and you're passing it a vector of vertices or integers. You're also copying the vector, which isn't your current problem, but isn't great for performance, especially given how large graphics buffers can get. Frankly, you're probably better just taking in a raw void pointer and data size.
    – vandench
    Jun 2 at 1:24
  • @van Ahhh okay, I understood incorrectly that the std::variant would allow me to input either vertex or uint32_t types to the function, not both at once. Is it possible to generalize the std::vector param to allow either/or? Do you also have any good resources to learn about using void pointers as inputs? I am totally unfamiliar with void pointers and how I would use them here. I appreciate your easily understandable explanation. Jun 2 at 2:14
  • 1
    Yes, templatize the vector argument. And for the love of god, always pass STL containers by reference, not by value.
    – Jherico
    Jun 2 at 3:11
  • 1
    VBO(this, vertices); should be in the member initializer list? In the body of the constructor it does nothing useful Jun 2 at 5:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.