0

I'm working on a test project for a file system i am developing. Part of the code writes device data to structures that will hold the Device name, Manufacturer, Drive type (CDR/CDRW/DVDRW/BLURAY/UDBR/etc..) and what media is in the device. These will be returned by ShellAPI functions from shellapi.h in windows.

however, I've come to a bit of an issue. I decided to create a universal function to get data stored within the structure, instead of creating 4 separate get instructions. So, i figured i'd use a lambdic expression to grab the data using a switch. but it doesn't work. it throws 2 errors.

Firstly, where i've placed the Lambic Expression is faulty. Intellisense throws a Auto is not allowed here error. This Lambda was placed within the protected section of my structure so it could reference the private data. Moving it outside of the structure removes this error, but casues referencing errors with the private data.

Secondly, when i initialize a secondary auto statement, Auto stor, i'm not quite sure how to initialize it properly. i tried assigning it void so that i could then push any other object to it, but it's apparently Too Vague for Intellisense.

In any case, i decided to go back to 4 Get/set functions for the time being, but i'm wondering what caused my errors and what i can do to not make the same mistakes next time.

TL;DR: Why Can't i use a lambda expression from within a structure?

TL;DR: Why can't auto be initialized to void(0)?

here is the code that was causing the errors:

typedef struct _MBCS_INTERNAL_DISK_STRUCT
{
   private:
     LPCWSTR *MBCSDeviceName;   //Disk Device Name
     LPCWSTR *MBCSManufacturer; //Disk Device Manufacturer
     MBCSDiskType diskType;     //Disk Drive Type
     MBCSMediaType mediaType;   //Disk Media Type
   protected:

     //get specified value.
     auto MBCSGetSpecifiedValue = [](_MBCS_INTERNAL_DISK_STRUCT *mbcsids, int i) 
    //Error: Auto is not Allowed Here?
    {
      auto stor = void(0); //Error: Indistiguishable Auto Declaration. Auto cannot be void?
      switch (i)
      {
        case 1: stor = &mbcsids->MBCSDeviceName;
        break;
        case 2: stor = &mbcsids->MBCSManufacturer;
        break;
        case 3: stor = &mbcsids->diskType;
        break;
        case 4: stor = &mbcsids->mediaType;
        break;
       default: stor = (int)(-1);
      }
      return stor;
    };

   public:

    //constructor
    _MBCS_INTERNAL_DISK_STRUCT(LPCWSTR a, LPCWSTR b, MBCSDiskType dt, MBCSMediaType mt)
    {
      MBCSDeviceName = &a;
      MBCSManufacturer = &b;
      diskType = dt;
      mediaType = mt;
    }

    //destructor
    ~_MBCS_INTERNAL_DISK_STRUCT()
    {
    }

}MBCSInternalDiskStruct;
  • As for `auto stor = void(0)`, void is an [incomplete type](http://stackoverflow.com/questions/25853258/why-cant-we-declare-a-variable-of-type-void) – user657267 Jul 27 '16 at 02:08
  • You're probably thinking of `void*` to hold a pointer to any object, not `void`. – chris Jul 27 '16 at 02:09

0 Answers0