Linked Questions

2 votes
4 answers
2k views

Motivation for mutable in C++ [duplicate]

Possible Duplicate: C++ 'mutable' keyword When have you used C++ 'mutable' keyword? I understand what mutable means and how it is used, What I would like to know is what is the ...
Alok Save's user avatar
  • 205k
1 vote
3 answers
6k views

Why is Mutable keyword used [duplicate]

Possible Duplicate: C++ 'mutable' keyword class student { mutable int rno; public: student(int r) { rno = r; } void getdata() const { rno = 90; ...
Ivin Polo Sony's user avatar
0 votes
1 answer
1k views

C++ keyword mutable [duplicate]

Possible Duplicate: C++ ‘mutable’ keyword What does the keyword mutable do in the following C++ code: class X { mutable int x; ... };
user231967's user avatar
  • 1,975
363 votes
19 answers
607k views

What is the difference between private and protected members of C++ classes?

What is the difference between private and protected members in C++ classes? I understand from best practice conventions that variables and functions which are not called outside the class should be ...
Konrad's user avatar
  • 40.5k
148 votes
7 answers
114k views

const before parameter vs const after function name in C++

What is the difference between something like this friend Circle copy(const Circle &); and something like this friend Circle copy(Circle&) const; I know const after the function is used to ...
jazzybazz's user avatar
  • 1,877
159 votes
9 answers
153k views

Why is there no Constant feature in Java?

I was trying to identify the reason behind constants in Java I have learned that Java allows us to declare constants by using final keyword. My question is why didn't Java introduce a Constant (const)...
gmhk's user avatar
  • 15.8k
55 votes
3 answers
25k views

__attribute__((const)) vs __attribute__((pure)) in GNU C

What is the difference between __attribute__((const)) and __attribute__((pure)) in GNU C? __attribute__((const)) int f() { /* ... */ return 4; } vs __attribute__((pure)) int f() { /* ......
wefwefa3's user avatar
  • 3,946
73 votes
1 answer
12k views

C++ Lambdas: Difference between "mutable" and capture-by-reference

In C++ you can declare lambdas for example like this: int x = 5; auto a = [=]() mutable { ++x; std::cout << x << '\n'; }; auto b = [&]() { ++x; std::cout << x << '\...
Sebastian Mach's user avatar
30 votes
4 answers
18k views

C++ Difference between const positioning

I'm struggling to get my head around the differences between the various places you can put 'const' on a function declaration in c++. What is the difference between const at the beginning: const int ...
user1055650's user avatar
30 votes
5 answers
644 views

Where are the readonly/const in .NET?

In C++ you'll see void func(const T& t) everywhere. However, i havent seen anything similar in .NET. Why? I have notice a nice amount of parameters using struct. But i see no functions with ...
user avatar
21 votes
6 answers
2k views

Is it bad practice for operator== to mutate its operands?

Scenario I have a class which I want to be able to compare for equality. The class is large (it contains a bitmap image) and I will be comparing it multiple times, so for efficiency I'm hashing the ...
JBentley's user avatar
  • 6,199
22 votes
1 answer
12k views

How to use a std::lock_guard without violating const correctness?

In a subclass, I have a private std::mutex m field that I use in an implementation of a base class pure virtual method to return a value in a thread-safe way (the value can be updated by another ...
w128's user avatar
  • 4,858
16 votes
4 answers
6k views

How to make a C++ map container where the key is part of the value?

I want to store a bunch of key-value objects, but where the value object itself (and references to it) knows its key. I also want to efficiently lookup these objects given only the key. class ...
Fire Lancer's user avatar
  • 29.8k
0 votes
4 answers
2k views

Is X const &x == X & const x?

I understand that X & const x is redundant. It is not ok! But I want to know what is the difference between X const &x and X & const x? Is the first expression saying that x is a ...
bespectacled's user avatar
  • 2,861
2 votes
5 answers
956 views

An operator == whose parameters are non-const references

I this post, I've seen this: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString& lhs, ...
isekaijin's user avatar
  • 19.6k

15 30 50 per page