use of deleted function error

SangminKim

i have had a problem with /usr/include/c++/4.6/ext/new_allocator.h:108:9: error: use of deleted function ‘SMIBQueue::SMIBQueue(const SMIBQueue&)’ with C++ eclipse.

and i am using -std=c++0x flag to use C++11

though i found the point that the error occur at, i don't know why.

this is header file

class SMIBQueue{
private:
    std::queue<unsigned char> exceptionQueue;
    std::queue<UserRequest*> userInputQueue;
    std::queue<LpRsp*> lpRspQueue;
    std::queue<LpCmd*> lpCmdQueue;

    std::mutex EvtQueueLock;
    std::mutex UserQueueLock;
    std::mutex LpRspQueueLock;
    std::mutex LpCmdQueueLock;
public:

    int evtGetItem(unsigned char &item);
    int evtPutItem(unsigned char item);
    int userGetItem(UserRequest*& item);
    int userPutItem(UserRequest* item);
    int lpGetItem(LpCmd*& queue_buf);
    int lpPutItem(LpCmd *queue_buf);
    int lpRspGetItem(LpRsp*& queue_buf);
    int lpRspPutItem(LpRsp *queue_buf);
    int lpRemoveQueuedInfo();
    int lpRspRemoveQueuedInfo();
};

class SMIBQueues{
public:
    static std::vector<SMIBQueue> smibQueues;
    static void queueInit(int numOfClient);
    static int evtGetItem(int sasAddr, unsigned char &item);
    static int evtPutItem(int sasAddr, unsigned char item);
    static int userGetItem(int sasAddr, UserRequest*& item);
    static int userPutItem(int sasAddr, UserRequest* item);
    static int lpGetItem(int sasAddr, LpCmd*& queue_buf);
    static int lpPutItem(int sasAddr, LpCmd *queue_buf);
    static int lpRspGetItem(int sasAddr, LpRsp*& queue_buf);
    static int lpRspPutItem(int sasAddr, LpRsp *queue_buf);
    static int lpRemoveQueuedInfo(int sasAddr);
    static int lpRspRemoveQueuedInfo(int sasAddr);
};

and this is the function that the error occur at

std::vector<SMIBQueue> SMIBQueues::smibQueues;

void SMIBQueues::queueInit(int numOfClient){
    for(int i = 0 ; i < numOfClient; i++){
        SMIBQueue s;
        smibQueues.push_back(s);
    }
}

in this function, push_pack method makes the error. when i eliminate the part, there is no problem while compiling.

Filip Roséen - refp

std::mutex has a deleted copy-constructor, this means that SMIBQueue will have its copy-constructor implicitly deleted since the compiler cannot generate one for you.

How would it go about copying a class which has members that cannot be copied? You will explicitly need to define your own copy-constructor if you want SMIBQueue to be copyable.


WHERE DOES MY CODE REQUIRE A COPY TO BE MADE?

When you are calling smibQueues.push_back (s) a copy of s will be stored inside smibQueues, which requires (the implicitly deleted) copy-constructor.

You can circumvent this specific problem by using smibQueues.emplace_back () to default-construct a SMIBQueue directly inside your smibQueues (ie. std::vector).

Note: Just keeo in mind that smibQueues might require SMBIQueue to be copyable/movable during other operations, such as if it tries to resize the underlying buffer, etc.


RECOMMENDED SOLUTION

Define your own copy-constructor if you plan to use it in contexts which require copying, but do keep in mind that std::mutex is neither copyable or movable, according to the Standard.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++ Use of deleted function error

From Dev

C++: avoiding the "use of deleted function" error

From Dev

Error: use of deleted function when I try to use a reference

From Dev

Xcode 7: C++ threads ERROR: Attempting to use a deleted function

From Dev

"Use of deleted function" error with std::atomic_int

From Dev

error: use of deleted function bool regex_match with gcc 5.2.0

From Dev

C++ lambda as argument. error: use of deleted function

From Dev

C++ lambda as argument. error: use of deleted function

From Dev

use of deleted function - std::atomic

From Dev

Use of deleted function with boost::bind

From Dev

use of deleted function CONSTRUCTOR, no matching function for call to

From Dev

error: use of deleted function ‘std::thread::thread(const std::thread&)'

From Dev

Error: use of deleted function std::basic_ofstream (OpenCV and C++11)

From Dev

Error: use of deleted function ‘test::test (const test&) C++ in combination with a vector

From Dev

C++ use of deleted function on GCC but not on MSVC

From Dev

C++ use of deleted function on GCC but not on MSVC

From Dev

Error: cannot call function of deleted QObject

From Dev

C++ functor passing through recursion: "attempt to use a deleted function"

From Dev

C++ std::thread "Attempt to use a deleted function"

From Dev

'use of deleted function' when merging two vectors of unique_ptr

From Dev

C++ functor passing through recursion: "attempt to use a deleted function"

From Dev

error C2280: attempting to reference a deleted function (atomic<int>)

From Dev

error C2280: attempting to reference a deleted function

From Dev

Qt compile error: C2280: attempting to reference a deleted function

From Dev

Visual Studio C++ reference deleted function compile error

From Dev

Return instance causes 'attempting to reference a deleted function' error

From Dev

Multilevel inheritance error C2280: "atttempting to reference a deleted function"

From Dev

Invalid use of function error

From Dev

attempting to reassign std::function with std::bind and getting error "attempting to reference a deleted function"

Related Related

  1. 1

    C++ Use of deleted function error

  2. 2

    C++: avoiding the "use of deleted function" error

  3. 3

    Error: use of deleted function when I try to use a reference

  4. 4

    Xcode 7: C++ threads ERROR: Attempting to use a deleted function

  5. 5

    "Use of deleted function" error with std::atomic_int

  6. 6

    error: use of deleted function bool regex_match with gcc 5.2.0

  7. 7

    C++ lambda as argument. error: use of deleted function

  8. 8

    C++ lambda as argument. error: use of deleted function

  9. 9

    use of deleted function - std::atomic

  10. 10

    Use of deleted function with boost::bind

  11. 11

    use of deleted function CONSTRUCTOR, no matching function for call to

  12. 12

    error: use of deleted function ‘std::thread::thread(const std::thread&)'

  13. 13

    Error: use of deleted function std::basic_ofstream (OpenCV and C++11)

  14. 14

    Error: use of deleted function ‘test::test (const test&) C++ in combination with a vector

  15. 15

    C++ use of deleted function on GCC but not on MSVC

  16. 16

    C++ use of deleted function on GCC but not on MSVC

  17. 17

    Error: cannot call function of deleted QObject

  18. 18

    C++ functor passing through recursion: "attempt to use a deleted function"

  19. 19

    C++ std::thread "Attempt to use a deleted function"

  20. 20

    'use of deleted function' when merging two vectors of unique_ptr

  21. 21

    C++ functor passing through recursion: "attempt to use a deleted function"

  22. 22

    error C2280: attempting to reference a deleted function (atomic<int>)

  23. 23

    error C2280: attempting to reference a deleted function

  24. 24

    Qt compile error: C2280: attempting to reference a deleted function

  25. 25

    Visual Studio C++ reference deleted function compile error

  26. 26

    Return instance causes 'attempting to reference a deleted function' error

  27. 27

    Multilevel inheritance error C2280: "atttempting to reference a deleted function"

  28. 28

    Invalid use of function error

  29. 29

    attempting to reassign std::function with std::bind and getting error "attempting to reference a deleted function"

HotTag

Archive