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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:13:23+00:00 2026-06-02T04:13:23+00:00

There is a snippet from my code: const std::pair<Info, const ElementHandler&>& handle () const

  • 0

There is a snippet from my code:

const std::pair<Info, const ElementHandler&>& handle () const {
                    FileHandler fileHandler = FileHandler();
                    std::pair<Info, const ElementHandler&> result = std::pair<Info, const FileHandler&> ( info, fileHandler );
                    return result;
                }

I have the following compilation error:

error: cannot declare field ‘std::pair<Synchronizer::Info, Synchronizer::ElementHandler>::second’ to be of abstract type ‘Synchronizer::ElementHandler’

How I can write the code to preserve the idea? Is it possible, or I need use pointers and dynamic allocation?

  • 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-02T04:13:25+00:00Added an answer on June 2, 2026 at 4:13 am

    “Avoid dynamic allocation in local scope”.

    If that’s the driving need behind your broken code, then I won’t follow the trend by telling you how to fix it to do what you don’t want ;-). Instead, you have to consider the implications properly. You must have some variable with a scope that matches the caller’s needs. Local automatic variables must be ruled out – they are destroyed when the function returns. So, you could:

    • use a function scoped static variable, or a global variable, but that will be the same variable each time the function is called and there could be thread-safety issues (your compiler may support some thread-specific keyword, and POSIX has functions to support thread-specific data – but 1-object-per-thread may still be too limiting)
    • create some buffer with space for many variables, and take control of their lifetime and reuse in some way that suits the client code (e.g. rotate through an array knowing that the client will release them in the order they’re returned and never need more than the array size concurrently)
    • let the client code worry about lifetimes (they probably know more than you) and provide a variable you’re to load with the result (e.g. bool load_my_x(X&);)
      • a problem here is that the caller needs to allocate space for FileHandler and not simply ElementHandler
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe there's a typo on this code snippet extracted from Stroustup's book, at
Code snippet from here : void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char
I have the following code snippet from a HTML file: <div id=rwImages_hidden style=display:none;> <img
Is there any good tutorial or code snippet out there on how to use
I have this snippet and there are 3 images and 3 folders in the
In the pickle module documentation there is a snippet of example code: reader =
There is a code snippet presented in The Pragmatic Programmer on page 143 as:
Here's a snippet of code from an sqlite database application I'm working on: my
Is this valid/portable/legal code: class Vector3 { public: float& operator [] ( const size_t
I don't have much experience doing unit testing. From what I learned, code should

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.