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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:21:49+00:00 2026-05-30T13:21:49+00:00

I have the following code: void cStatisticDBSerializer::GetStats (std::map <std::string, long long >& ioCounterStats, std::map

  • 0

I have the following code:

void cStatisticDBSerializer::GetStats (std::map <std::string, long long >& ioCounterStats,
                                       std::map <std::string, long long >& ioGaugeStats,
                                       bool iSwitch)
{
   // Before getting the stats, clear the containers 
   ioCounterStats.clear ();
   ioGaugeStats.clear ();

   std::map <std::string, long long >& lStats = ioCounterStats;

   if (iSwitch)
   {
      lStats = ioGaugeStats;
   }

   // Do something with lStats
}

The question is: Is it valid to assign the function input reference to the local variable lStats? For some reason, this compiles fine, but does not behave as expected. However, if I change lStats to a pointer and assign it as follows (e.g.):

std::map <std::string, long long >* lpStats = &ioCounterStats;

It works just fine.

Could somebody please explain what’s going on here. Thanks!

  • 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-30T13:21:50+00:00Added an answer on May 30, 2026 at 1:21 pm

    You can’t reassign a reference once it has been created. Instead every use of it will “refer” to the original assignment. Your first example is equivalent to:

    ioCounterStats /*lStats*/ = ioGaugeStats;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public void post(String message) { final String mess =
I have following code public class TEST { public static void main(String arg[]){ try
i have following pseudo code : void siftup(int n) pre condition n>0 && heap(1,n-1)
I have the following code: void Foo() { static std::vector<int>(3); // Vector object is
I have the following code static void Main(string[] args) { //var source = BlockingMethod();
Currently I have The following code: void Page_Load(object sender, System.EventArgs e) { string connectionString
I have the following code: private void Process(string path) { using (FileStream fs =
I have the following code - (void) viewWillAppear:(BOOL)animated { NSLog(@dismiss view); [self dismissModalViewControllerAnimated:YES]; }
I have the following code: void readFile(BST *tree) { ifstream infile(input.txt); long int sid,
I have the following code: -(void)viewWillAppear:(BOOL)animated { UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface]; if(orientation==UIDeviceOrientationLandscapeLeft

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.