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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:16:21+00:00 2026-05-26T22:16:21+00:00

In my class I have a member: std::vector<std::string> memory_; Now I’d like to have

  • 0

In my class I have a member:

std::vector<std::string> memory_;

Now I’d like to have a fnc returning what’s in the memory’s first element but I do not want to specify std::string as a return type in case later I decide to use different type for this purpose so I’ve tried this but it doesn’t work:

typename decltype(memory_)::value_type call_mem()
{
    return memory_[0];
}

Any ideas how to specify return type in the most generic way?

  • 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-05-26T22:16:21+00:00Added an answer on May 26, 2026 at 10:16 pm

    As long as you use a standard container, that should work, and I think is okay.

    Alternatively, since it is a member of a class, then you can use typedef and expose the value_type as nested type of the class:

    class demo
    {
       public:
         typedef std::vector<std::string> container_type;
         typedef container_type::value_type value_type;
    
         value_type call_mem()
         {
             return *std::begin(memory_); //it is more generic!
         }
    
       private:        
         container_type memory_;
    };
    

    Note that *std::begin(memory_) is more generic than both memory_[0] and *memory_.begin() as with it, even arrays would work, but that is less likely to benefit you in real code.

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

Sidebar

Related Questions

I have a class Message that has a std::string as a data member, defined
I have a class in C++ with the following member: map< someEnum, vector<SomeObject*>* >
I have a class with a static std::map member variable that maps char s
I have a question about performance of move constructor, pseudo C++ class: typedef tuple<std::string,
let's say i want to have a member variable for a pointer to std::vector
I have a vector of A objects. class A contains a member object of
I started to write a class which would act much like the std::vector but
If I have a vector as a private member in my class, what's the
I have a class which have a static member. As I understand, all static
Is there a way to require that a class have a particular abstract member?

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.