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

  • SEARCH
  • Home
  • 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 8838651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:03:32+00:00 2026-06-14T10:03:32+00:00

Lately I have been working through Meyers’ Effective C++ Third Edition. For a project

  • 0

Lately I have been working through Meyers’ Effective C++ Third Edition. For a project I am currently working on I have had to create a class that I explicitly want to disallow the use of compiler generated functions. I implemented code using Item 6 in said book as a reference, the only major difference in that my class is Templated. The code for it is as follows

template <class T>
class Uncopyable
{
protected:
    Uncopyable<T>(){}
    virtual ~Uncopyable<T>(){}
private:
    Uncopyable<T>(const Uncopyable<T>&);
    Uncopyable<T>& operator=(const Uncopyable<T>&);
};

My test function.

class Test : private Uncopyable<Test>
{
public:
    Test(){}
    ~Test(){}
    inline void test()
    {
        std::cout << "blah" << std::endl;
    }
private:
protected:
};

When used like this the code works completely as expected

int main(int argc, char* argv[])
{
    Test t1, t2;

    // Works as expected, doesnt allow copying of object
    t2 = t1;
    // and this works fine, no copying
    Test t3 = t2;

    // finally, works correctly no copying is allowed
    Test t4(t1);

    return 0;
}

When used like this however, the code compiles fine and copying can take place, when it should not be able to?

int main(int argc, char* argv[])
{
    Test* t1 = new Test(), *t2;
    t1->test();
    // Works when it shouldnt work?
    t2 = t1;
    t2->test();

    // same with this
    Test* t3 = t2;
    t3->test();

    // and this
    Test* t4(t1);
    t4->test();

    delete t1;

    return 0;
}

I have tried it without the template class and the result is the same, so I don’t think that is the issue.

So SO, why is this allowed to happen? Is there an error in my code, or am I just understanding the concept wrong? Thanks.

  • 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-14T10:03:33+00:00Added an answer on June 14, 2026 at 10:03 am

    You’re copying the pointer, not the object. Try this:

    *t2 = *t1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation I have been working on a project lately where the UI development seems
I have been working with SharpSVN quite a bit lately and I'm currently trying
I am currently working on a website and lately have been using GD with
I have been working with some bash scripting lately and been looking through the
I have been working on packing a project lately but it has turned into
I have been working on Neural Networks for various purposes lately. I have had
I have been working lately on a number of iterative algorithms in MATLAB, and
I have been working with Exceptions lately. I think it makes sense to log
I am a photographer and I have been working on redesigning my website lately.
I've been having some strange errors lately. I have a working install of Git,

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.