Am I nuts?

Oct. 25th, 2006 03:56 pm
pphaneuf: (Default)
[personal profile] pphaneuf
I'm rather offended, having been bitten by this bug. Why is it even allowed to take a reference to a const reference, if it could be a copy?!?

#include <assert.h>

class Blah
{
public:
  const unsigned int &myfoo;
  Blah(const unsigned int &p):
    myfoo(p) {}
  const unsigned int getfoo()
  {
    return myfoo;
  }
};

int main()
{
  int foo(42);
  Blah baz(foo);

  ++foo;

  assert(foo == baz.getfoo());

  return 0;
}
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

February 2016

S M T W T F S
 123456
7891011 1213
14151617181920
21222324252627
2829     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 24th, 2025 01:20 pm
Powered by Dreamwidth Studios