Is it possible to access object elements inside a Vector List?

  • Thread starter Thread starter ananda vardhana
  • Start date Start date
A

ananda vardhana

Guest
Hi,

The following program works perfect. However I dont like the way I am doing it. I am initializing the structure vmFeatures first and then pushing into the Vector. That is a long way. I feel there must be easier way where I dont have to do the two steps but just push it straight to the vector list. What I mean is do something like this. Just with one push or do it in multiple lines but ultimately just to one push when all data has been initialized. Instead of Vector String i had declared it as a array with index it would be very easy to do it.

The following code does not work but that is how I wish things worked.

VM_FEATURES vmFeatures, vmFeaturesPop;
// Basically push all the values for one entry in the vector list in one line and then push again in a loop
GPspFeatures.VmVpFeatures.push< ExecutionState = TRUE, SocketID = 0x1234, SystemId.push_back(L"0x234234"), VmName.push_back(L"MyVM1234"), VpPerVm = 23)

The following program works but not the way I want

#include <windows.h>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

typedef struct _VM_FEATURES
{
vector<wstring> VmName;
vector<wstring> SystemId;
UINT32 SocketID;
UINT32 VpPerVm;
bool ExecutionState; // Running or other state (Off, saved, waiting ... )
} VM_FEATURES, * PVM_FEATURES;

typedef struct _PSP_FEATURES // Later on the plan is to fill with other devices like Containers, Storage
{ // RDT_FEATURES will contain info on devices supported.
vector<VM_FEATURES> VmVpFeatures;
} PSP_FEATURES, * PPSP_FEATURES;

PSP_FEATURES GPspFeatures;

int main()
{

VM_FEATURES vmFeatures, vmFeaturesPop;
vmFeatures.ExecutionState = TRUE;
vmFeatures.SocketID = 0x1234;
vmFeatures.SystemId.push_back(L"0x234234");
vmFeatures.VmName.push_back(L"MyVM1234");
vmFeatures.VpPerVm = 23;
GPspFeatures.VmVpFeatures.push_back(vmFeatures);
vmFeaturesPop = GPspFeatures.VmVpFeatures.back();
GPspFeatures.VmVpFeatures.pop_back();
return 0;
}

Thanks

Continue reading...
 
Back
Top