Questions tagged [deleted-functions]

A function in C++11 which is defined as deleted. Either it is explicitly deleted using "= delete", or it is implicitly deleted by the compiler.

deleted-functions
Filter by
Sorted by
Tagged with
1 vote
1 answer
52 views

Example of "implicit ODR-use of a non-pure virtual member function that happens to be deleted"

There is a sentence in the cppreference.com description of Deleted functions: However, implicit ODR-use of a non-pure virtual member function that happens to be deleted is allowed. Could you provide ...
Кое Кто's user avatar
2 votes
0 answers
87 views

Why - in that example with an extended lambda - is an ambigious copy constructor and some deleted function

I do not understand the behaviour of the following code: template< bool b > struct Foo { Foo() = default; __host__ Foo( const Foo & ) requires( b ) {} __device__ Foo( const Foo &...
tommsch's user avatar
  • 658
3 votes
1 answer
74 views

Effect of user deleted auto constructors on implicit generation of copy constructors

How does user deleted auto constructors affect implicit generation of copy constructors? For eg: struct Foo { Foo(X) = delete; auto operator=(X) = delete; }; int main() { Foo a; Foo b(...
Sourav Kannantha B's user avatar
0 votes
0 answers
82 views

QT QML QAbstractListModel deleted function error

I am trying to pass a c++ user model to qml and get an error that I don't understand. I use a manager class that should reads in the users and fills the listmodel. The list model itself should be pass ...
user2377283's user avatar
0 votes
0 answers
55 views

Explicitly deleted functions

we are migrating code to VS 2019 from legacy code We have an overloaded function on operator '<<' that is invoking basic_ostream function when executing the following lines. CStringArray asLine; ...
Madhu Rao's user avatar
1 vote
1 answer
105 views

Find Functions Stored in Running Python Kernel

I've done something stupid in Python, in Jupyter notebook. I deleted the cell that had my functions in it, probably a couple of hours ago, and now I don't have them any more. However, I can still run ...
Anna's user avatar
  • 21
0 votes
1 answer
188 views

Deriving from a class with a deleted destructor?

I am using CRTP to create a counter class, similar to Object Counter Additionally, classes that derive from this counter also should not be destructible. It will look something like this template <...
Nathan29006781's user avatar
5 votes
1 answer
425 views

Detect deleted function

Is there a way to detect deleted functions after overload selection (over no viable or ambiguous overloads)? void foo(); void foo(double) = delete; void foo(std::string); void foo(char, int); void ...
Jarod42's user avatar
  • 210k
1 vote
2 answers
635 views

C2280 error attempint to reference a deleted function [duplicate]

The function DataContainer.initial() triggers a C2280 error. After defining a move assignment operator it works. But I am not clear why in function initial_2() it works. The obvious difference is that ...
stevenhz's user avatar
0 votes
1 answer
769 views

Initializing unique_ptr causes an "error: use of deleted function" even though it's "std::move"ed

I am writing code that passes a std::unique_ptr through a few layers that look bad, but I don't have a choice but pass it all along for now. The problem is that I am getting an error when I try to ...
user2465084's user avatar
3 votes
1 answer
1k views

Is "implicitly deleted" constructor =delete or not declared at all? [duplicate]

Given the following toy code: class X { public: X() { } X(const X&) { } //X(X&&) = delete; }; int main() { X x; X y = std::move(x); } I know that X::X(X&&) is ...
CPPL's user avatar
  • 812
1 vote
1 answer
384 views

Does the return type of a deleted operator matter if the operator is deleted?

I am reading ‘C++ concurrency in action’, one page talks about copy-assignment operator =delete. I have googled about it (Deleting copy constructors and copy assignment operators. Which of them are ...
potter john's user avatar
0 votes
2 answers
418 views

Why can't the map be initialized?

Given the following code, #include <iostream> #include <string> #include <mutex> #include <string_view> #include <unordered_map> struct sstruct { std::string content;...
Alberto Tiraboschi's user avatar
1 vote
1 answer
334 views

Deleted function error after using random lib in struct

I'm trying to write a simple struct around an std random number generator. According to the compiler I can initialize this class but when I try to use the function it gives the following error: Error ...
zarro's user avatar
  • 35
1 vote
1 answer
404 views

Should I put deleted member function in uml class diagram?

Should I put deleted method or member function in an UML class diagram, i.e. for example for a class like this: class ProfilometerManager { int a = 6; public: ProfilometerManager(...
Gameriker's user avatar
43 votes
2 answers
3k views

Can one delete a function returning an incomplete type in C++?

In the following example function f() returning incomplete type A is marked as deleted: struct A; A f() = delete; It is accepted by GCC, but not in Clang, which complains: error: incomplete result ...
Fedor's user avatar
  • 18.5k
5 votes
0 answers
69 views

Finding specific function calls by means of C++ compiler

I have a big codebase and would like to find calls to specific standard or third-party library functions. If the names of the functions are not very unique and can be present also as names of ...
Fedor's user avatar
  • 18.5k
1 vote
1 answer
191 views

Explicit instantiation of a deleted function template in C++

If a function template is marked as deleted, is it allowed to explicitly instantiate it as in the example: template<class T> int foo(T) = delete; template int foo(int); Clang and GCC allows it,...
Fedor's user avatar
  • 18.5k
0 votes
1 answer
191 views

Compiler error on call to recursive function - "attempting to reference a deleted function"

I'm trying to write a binary tree to a file using a recursive function. The call to writeFile(std::string fileName) opens the file stream and then passes it to the recursive function call, writeFile(...
Kurt's user avatar
  • 3
1 vote
3 answers
2k views

Error: Use of deleted function std::unique_ptr

I am trying to pass a unique_ptr into a custom vector class but I am receiving the error in the subject title. I understand that you cannot copy a unique_ptr and so I am trying to use std::move() when ...
Max Peglar-Willis's user avatar
1 vote
1 answer
158 views

C++ primer 5th edition: Synthesized Move constructor as deleted and copy-constructor

I'm on the last appendix of C++ primer 5th edition. (Solution part): Here is an example from there: Assume Y is a class that defines its own copy-constructor but not a move-constructor struct hasY{ ...
Itachi Uchiwa's user avatar
-1 votes
2 answers
683 views

Is it possible to free dynamic objects created via new using free? [duplicate]

I know that C++ allows creating a class with a deleted or inaccessible destructor: struct Foo{ Foo() = default; ~Foo() = delete; }; Foo f;// error: ~Foo is deleted Foo* pf = new Foo();// ok ...
Itachi Uchiwa's user avatar
5 votes
2 answers
850 views

Would a derived class ever have an implicit copy constructor or assignment operator when it's deleted in the base class?

Qt defines Q_DISABLE_COPY as follows: #define Q_DISABLE_COPY(Class) \ Class(const Class &) = delete;\ Class &operator=(const Class &) = delete; Q_DISABLE_COPY is used in the ...
Joseph Sible-Reinstate Monica's user avatar
0 votes
1 answer
292 views

Add class containing a circular buffer to Vector

I am trying to create a vector filled with class objects, and the class objects contain circular buffers as one of their members. I am running into this error: In file included from .pio/libdeps/...
Spencer Brennessel's user avatar
0 votes
0 answers
50 views

Use of deleted function [duplicate]

Hello newbie programmer here. Please help me. What should I do? #include <iostream> #include <string> using namespace std; class Konut { public: int yas; int metrekare; int ...
Gökhan's user avatar
  • 19
0 votes
0 answers
323 views

axios delete operation with use reducer in react js

i am working on crud operation with context api and use reducer. i fetch data from an api and store it as initial value. but now i am confused how to delete a user from my fetched list. i made a ...
hashmi44489's user avatar
3 votes
0 answers
304 views

Why my compiler doesn't allow overriding a deleted non-throwing virtual member function as a deleted throwing member function?

I've read from C++ primer 5th ed. That a virtual member function that won't throw (noexcept) must be overriden as non-throwing function. The exception is if the virtual member function is defined as a ...
Maestro's user avatar
  • 2,512
0 votes
1 answer
442 views

Attempting to reference Deleted function shared_ptr

i have the following code inline entity_ptr Parser::parse(const std::string& json_str) { // std::cout << "parse: " << json_str << "\n"; entity_ptr ...
Zakkar's user avatar
  • 3
0 votes
1 answer
117 views

How do I assign an object containing an unique_ptr to a vector of its type when a move assignment operator is defined?

The self-contained program section below leads to this error on Visual Studio 2019: "function "partition_data::operator=(const partition_data &)" (implicitly declared)" is a ...
user151387's user avatar
2 votes
0 answers
335 views

How do I fix attempting to reference deleted function error in C++ sfml

this is main.cpp #include <SFML/Graphics.hpp> #include <iostream> #include<windows.h> #include <string> #include "class.cpp" using namespace sf; int main() { ...
luka rekhviashvili's user avatar
4 votes
2 answers
425 views

C++ and ExprTk parser "use of deleted function" error

I'm trying to use the ExprTk mathematical expression parser library within a class whose objects are to be stored in a vector of objects, which is a member variable of another class; however, when I ...
mrmudd's user avatar
  • 61
0 votes
1 answer
53 views

Conditions to declare function deleted by c++

ALL, What are the conditions where the compiler itself declares the function deleted? Consider following: class Foo { public: Foo(); virtual void func1() = 0; virtual void func2() = 0; ...
Igor's user avatar
  • 5,809
-1 votes
1 answer
133 views

how to return the result of addition of two objects of a class

On compiling it is showing sme error like use of delete function constexpr Player::Player(const Player&) when it is return the result of addition of the objects. #include <bits/stdc++.h> ...
Vansh_Chaudhary's user avatar
2 votes
1 answer
558 views

std::map: Creating/replacing an element when it is not default-constructible

Suppose you have a class which is not default constructible. class A { private: int a; public: A() = delete; A(int a0) : a(a0) {} }; Now, we have some map Int --> A, std::map<int, ...
buj's user avatar
  • 165
1 vote
2 answers
156 views

Why does copy-and-swap in a base class cause the copy-assignment operator to be implicitly deleted in the derived class?

Tested only in GCC and Clang, the presence of a pass-by-value copy assignment operator in the base class (useful when implementing the copy-and-swap (or copy-and-move) idiom) causes the copy ...
SumDood's user avatar
  • 304
0 votes
1 answer
189 views

Trying to locate a deleted function

Messing around in C++ for class and came across a error stating that i was trying to reference a deleted function. Here is the error C2280(Test &Test::operator = (const Test& : attempting ...
CluelessCollegeStuden's user avatar
-1 votes
1 answer
409 views

Equal operator attempting to reference a deleted function, array

I am using SFML to create a space invaders clone with C++. I am quite new to C++ and I'm learning it as I'm working on this project. I am getting the following error when trying to create a new enemy ...
firepro20's user avatar
2 votes
2 answers
267 views

C++ Problems Pushing Initializer List onto a Standard Vector If the Struct Contains a Mutex

I'm currently working on a project in C++ in which I have a list of structs stored in a vector that have a lot processing associated with them. In order to speed things up, I've chosen to split the ...
Ashton Stephens's user avatar
2 votes
0 answers
54 views

Will containing a `std::unique_ptr` make the default copy constructor a deleted function? [duplicate]

The fact that unique_ptr doesn't allow copy which means no more than one object can share the same underlying data. If I contain an object of unique_ptr in my class will the compiler be wise enough to ...
Itachi Uchiwa's user avatar
0 votes
0 answers
52 views

Why does this temporary created with deleted constructor compile? [duplicate]

This code: struct F { F() = delete; void foo() {}; }; int main() { F{}.foo(); } Live demo here. Suffice to say I would assume it to not compile (as we're calling a deleted constructor)....
rubenvb's user avatar
  • 75.6k
2 votes
2 answers
893 views

Inheritance of =delete functions

let's say I have a class named File. I want to disable the copy constructor for every son of File, for example TextFile. Would doing something like this will still disable the copy constructor of ...
איתן לוי's user avatar
8 votes
1 answer
955 views

Initialisation of aggregate with default constructor deleted in c++20 [duplicate]

There is a struct containing POD and default constructor deleted. Trying to aggregate-initalize an instance of the struct results in compilation error in g++9.1 when compiled with -std=c++2a. The same ...
Alexey R.'s user avatar
  • 183
0 votes
2 answers
201 views

Resolving a compiler error due to an invariant member with a possible deleted default constructor

I have asked a series of questions that all relate to the same source code in this order: experimenting-with-unions-and-bitfields-within-a-structures-and-templates trying-to-flip-the-order-of-...
Francis Cugler's user avatar
-1 votes
2 answers
192 views

C++ Error (C2280) tring to access a deleted function [closed]

So, i was trying to make a 2d game with opengl and sfml, so i created a button class in an input namespace, i made a render() function in it, but when i call it (no matter wheter i use a pointer or i ...
Chappie733's user avatar
41 votes
5 answers
5k views

Deletion of copy-ctor & copy-assignment - public, private or protected?

In order to make an object non-copiable we can explicitly delete both its copy-constructor and copy-assignment operator. My question is: What is the right place to do it - in the public, private or ...
Sajal's user avatar
  • 1,823
9 votes
3 answers
3k views

Is deleting copy and move constructors/assignment operators in base class enough?

If I have an abstract base class and I want to make all derived classes noncopyable and nonmovable is it sufficient to declare these special member functions deleted in the base class? I want to ...
Mike Sweeney's user avatar
  • 1,976
0 votes
2 answers
296 views

Force compiler to emit error on move constructor not defined with a base class deleted copy ctor

Consider a base class which prevents copy construction and copy assignment like this: class NonCopyable { public: NonCopyable() = default; ~NonCopyable() = default; ...
Ayak973's user avatar
  • 453
3 votes
3 answers
274 views

C++11 deleted/defaulted constructors

I'm a bit confused about how/why the constructors are called in C++11 and C++17. #include <iostream> using namespace std; //--- template<typename T> struct StructTest { public: const ...
Andy's user avatar
  • 137
14 votes
2 answers
1k views

std::vector::push_back() doesn't compile on MSVC for an object with deleted move constructor

I have a class with a deleted move constructor and when I try to call std::vector::push_back() in MSVC (v.15.8.7 Visual C++ 2017) I get an error saying that I am trying to access the deleted move ...
Brent's user avatar
  • 143
0 votes
1 answer
323 views

C++ Poco - How to create a vector of NotificationQueue's?

I want to create a Notification Center, where I handle all the notifications to threads. I can't tell on the software boot how many notification queues I would need. It may vary during run-time. So ...
waas1919's user avatar
  • 2,505