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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:33:43+00:00 2026-05-31T00:33:43+00:00

I wrote class with template. class has map as member and some getxxx() /

  • 0

I wrote class with template. class has map as member and some getxxx() / setxxx() member functions.

template<typename T1,typename T2>
class C1{
    map<T1,T2> M;
public:
    map<T1,T2> getM();
    T2 getMvalue(T1 Key);
    void setM(T1 key,T2 Value);
};

here I want to implement getMvalue(), where it recieves key as argument and returns the corresponding “value” if “key” is available in mapM.

It look something like…

template<typename TKey,typename TValue>
T2 C1<T1,T2>::getMvalue(T1 Key){
    if(M.count(Key)>0)
        return M[Key];
    else
        return(???);
};

Here I need to use something in place of ???. keeping in mind that return type of function is T2, which can be anything depending on user decision.
How can i replace “???” and with what?

  • 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-31T00:33:45+00:00Added an answer on May 31, 2026 at 12:33 am

    I would encourage you to use the TryGet pattern

    template<typename TKey,typename TValue>
    bool C1<T1,T2>::tryGetMvalue(T1 key, T2& value){
        if(M.count(key)>0) {
            value = objProperties[key];
            return true;
        }
        return false;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following program #include <iostream> template<typename C, typename Res, typename... Args> class
I have a template class which has a static pointer-to-member, like this: template<class T,
I have a template statistics class that has range parameters. template <typename T> class
Given a template class as such: template <typename TYPE> class SomeClass { public: typedef
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I'm sure that boost has some functions for doing this, but I don't know
I want to write a template function that checks some Timestamp property (class inherits
I am trying to understand some C++ syntax: template<class T> class Foo { Foo();
I want to export a C++ class, which has a member std::vector<int> . How
I wrote a little class for storing global variables/functions. My question is - is

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.