lundi 19 novembre 2018

Avoid calling move constructor

I have following example

#include <cstdint>

class FooC
{
public:
   FooC(uint16_t iPort, uint16_t iPin)
   : PORT(iPort)
   , PIN(iPin)
   {
   };

   ~FooC() = default;

   FooC() = delete;
   FooC(const FooC&) = delete;
   FooC(FooC&&) = delete;

private:
   const uint16_t PORT;
   const uint16_t PIN;
};

int main()
{
    FooC array[2] = {
       FooC(1,2),
       FooC(3,4)
    };
}

and I don't want to call the default, move and copy constructor. Due to that I deleted the functions. Unfortunately this results in following error (compiled with C++11)

: In function 'int main()':

:28:5: error: use of deleted function 'FooC::FooC(FooC&&)'

 };

 ^

:16:4: note: declared here

FooC(FooC&&) = delete;

^~~~

:28:5: error: use of deleted function 'FooC::FooC(FooC&&)'

 };

 ^

:16:4: note: declared here

FooC(FooC&&) = delete;

^~~~

Compiler returned: 1

Is it possible to force in this example the calling of constructor with the parameters and still delete the default, move and copy constructor?

Aucun commentaire:

Enregistrer un commentaire