Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:34:40+00:00 2026-06-10T06:34:40+00:00

struct S { S() {} S (const S &) = delete; }; void f1

  • 0
struct S {
    S() {}
    S (const S &) = delete;
};

void f1 (S s) {}
void f2 (S &s) {}

int main() {
    S s;

    f2(s);
}

Since S(S &s) is deleted, why does using f2 not throw an error since when it was declared it passes in the arguments S &s? When I use f1(s) it throws an error. I’ve looked at the definition of deleted functions and I thought this would throw an error, but it doesn’t. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:34:42+00:00Added an answer on June 10, 2026 at 6:34 am

    Lets have a look at S:

    struct S {
        S() {}                   // default constructor
        S (const S &) = delete;  // copy-constructor
    };
    

    What you have here is a type that can be constructed, but cannot be copied.

    Now lets take a look at your functions:

    void f1 (S s1) {}    // creates a local copy of its parameter
    void f2 (S &s2) {}   // takes a reference to the parameter
    

    When you call f1(s), the function tries to create a copy of s – but your type S forbids copying – that’s why this does not work.

    When you call f2(s), the function creates a reference to its parameter – so whatever you do inside f2 with s2 is done directly to the original object s. There is no way a class can prevent anybody to take a reference of the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

struct Foo { int data; Foo() = default; Foo(const Foo& arg) = default; };
I've got class which is using plain-only-data struct with const variables and I'm not
Consider the following code: struct Calc { Calc(const Arg1 & arg1, const Arg2 &
Consider the following code: struct Foo { Foo operator+(const Foo &rhs) const; // notice
See the following: struct A { std::string* get() const { //return const_cast<std::string*>(&m_pObj); return &const_cast<A*>(this)->m_pObj;
struct Node { int value Node* next; } typedef List Node* const Set operator
#include <exception> struct empty_stack: std::exception { const char* what() const throw(); }; template<typename T>
Consider the following code snippet: #include <iostream> using namespace std; struct Element { void
Code: struct A{ const bool const_some_write_once_flag; A(): const_some_write_once_flag(false) { } }; struct B: public
In code: struct Rep { const char* my_data_; Rep* my_left_; Rep* my_right_; Rep(const char*);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.