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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:10:15+00:00 2026-06-06T11:10:15+00:00

More C++ learning questions. I’ve been using vectors primarily with raw pointers with a

  • 0

More C++ learning questions. I’ve been using vectors primarily with raw pointers with a degree of success, however, I’ve been trying to play with using value objects instead. The first issue I’m running into is compile error in general. I get errors when compiling the code below:

class FileReference {

    public:
        FileReference(const char* path) : path(string(path)) {};
        const std::string path;

};

int main(...) {

    std::vector<FileReference>  files;

    // error C2582: 'operator =' function is unavailable in 'FileReference'
    files.push_back(FileReference("d:\\blah\\blah\\blah"));

}

Q1: I’m assuming it’s because of somehow specifying a const path, and/or not defining an assignment operator – why wouldn’t a default operator work? Does defining const on my object here even I’m assuming it’s because I defined a const path, Does const even win me anything here?

Q2: Secondly, in a vector of these value objects, are my objects memory-safe? (meaning, will they get automatically deleted for me). I read here that vectors by default get allocated to the heap — so does that mean I need to “delete” anything.

Q3: Thirdly, to prevent copying of the entire vector, I have to create a parameter that passes the vector as a reference like:

// static
FileReference::Query(const FileReference& reference, std::vector<FileReference>& files) {
    // push stuff into the passed in vector
}

What’s the standard for returning large objects that I don’t want to die when the function dies. Would I benefit from using a shared_ptr here or something like that?

  • 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-06T11:10:19+00:00Added an answer on June 6, 2026 at 11:10 am
    1. If any member variables are const, then a default assignment operator can’t be created; the compiler doesn’t know what you would want to happen. You would have to write your own operator overload, and figure out what behaviour you want. (For this reason, const member variables are often less useful than one might first think.)

    2. So long as you’re not taking ownership of raw memory or other resources, then there’s nothing to clean up. A std::vector always correctly deletes its contained elements when its lifetime ends, so long as they in turn always correctly clean up their own resources. And in your case, your only member variable is a std:string, which also looks after itself. So you’re completely safe.

    3. You could use a shared pointer, but unless you do profiling and identify a bottleneck here, I wouldn’t worry about it. In particular, you should read about copy elision, which the compiler can do in many circumstances.

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

Sidebar

Related Questions

i just got some more questions while learning PHP, does php implement any built
I want to start learning more about using SWIG and other methods to interface
I have been reading through various questions on here, as I am learning VHDL
These questions are relatively straight forward. When using vectors, should I use the new
I'm still learning the dark arts of TDD and recently I've been trying to
I have been learning about move constructors over the last day or so, trying
I've been learning more about Python recently, and as I was going through the
I am learning JPA and have one question: In which situations we need more
This is more of a question of syntactic elegance, but I'm learning C++ and
I am studying Python and currently going through some more learning with dictionaries. I

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.