dimanche 29 avril 2018

C++: The iterator of struct in the class pointed by the iterator of class pointer

In this code, 'vector iterator of class pointer' and 'vector iterator of struct' loops for total twice.

but with for (vector<VkQueueFamilyProperties>::iterator iter2..., the following exceptions caused:

vector iterator not dereferencable

Am I did the wrong way to access the iterator?

I want to know why the second iterator cannot be initialized.

class RVulkanDevice;
struct VkQueueFamilyProperties;

bool foundGraphic = false;
bool foundCompute = false;

// First Iterator (with vector of class pointer)
for (vector<RVulkanDevice*>::iterator iter
    = RVulkanDeviceClass.begin(); iter != RVulkanDeviceClass.end(); ++iter)
{
    (*iter)->GetPhysicalDeviceQueueFamilyProperties();

    // Second Iterator (with vector of first iterator's struct)
    // Before Breakpoint
    for (vector<VkQueueFamilyProperties>::iterator iter2
        = (*iter)->queueFamilyProps.begin(); iter2 != (*iter)->queueFamilyProps.end(); ++iter2)
    {
        // After Breakpoint
        if (iter2->queueFlags & VK_QUEUE_GRAPHICS_BIT) {
            foundGraphic = true;
        }
        if (iter2->queueFlags & VK_QUEUE_COMPUTE_BIT) {
            foundCompute = true;
        }
    }
}

Debugged with VS2017

Aucun commentaire:

Enregistrer un commentaire