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 8180569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:14:30+00:00 2026-06-07T00:14:30+00:00

have written this little class, which generates a UUID every time an object of

  • 0

have written this little class, which generates a UUID every time an object of this class is created.

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>    

class myClass {

public:

    boost::uuids::uuid GetUUID();

    virtual ~myClass();

    myClass() {   // constructor
        mId = boost::uuids::random_generator()();
        std::cout<< "object created with uuid " << mId <<std::endl;
    }

private:

    boost::uuids::uuid mId;

}

At some point, I am pushing these objects to a vector and equating that vector with another vector using simple assignment operator. To ensure the objects in the new vector do not generate new UUIDs, I want to write a copy constructor. But as you can see, the constructor needs no arguments. So I am not sure how to write the copy constructor. Moreover, if I have multiple variables instead of just one UUID, how do I handle that situation?

  • 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-07T00:14:30+00:00Added an answer on June 7, 2026 at 12:14 am

    You need the following signature:

     myClass(const myClass& other)
     {
         mId = other.mId;
     }
    

    and also the assignment operator

     myClass& operator=(const myClass& other)
     {
         mId = other.mId;
         return *this;
     }
    

    Note that if you don’t implement these, the compiler-generated ones will do a shallow copy, so no new UUIDs will be generated. But you should have them there to obey the rule of three (you do have a destructor after all).

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

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written this code in JavaScript and works perfectly fine when I include
i have written this tree class for a familytree now i need a search
I have written this clone method for when the parent of the Employee class
I've written this little test class to connect up to an FTP server. import
I have written a little class to persistently memoize some expensive functions that do
I have written a little helper function which performs some sort of drawing operations,
I have written a little PDF view which shows PDFs page by page to
Little silly question, but got stuck for a long time. I have written two
I'm having a hard time understanding TBB's enumerable thread specific. I have written this

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.