Questions tagged [const-pointer]

36 questions
0
votes
3 answers

invalid initialization of non-const reference of type std::string& - how to remove

I am getting an error: error: invalid initialization of non-const reference of type 'std::string& {aka std::basic_string&}' from an rvalue of type 'std::basic_string' The code is: const std::string& hitVarNameConst = (isKO ? "isKO" : "isKI"); for…
Mayank Raj
  • 121
  • 2
  • 12
0
votes
1 answer

Why can't I change address of a pointer of type `const int *` when passed as function argument?

As far as I know, const int * implies that I can change the pointer but not the data, int * const says that I can't change the pointer address but I can change the data, and const int * const states that I can't change any of them. However, I can't…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
0
votes
2 answers

new-expression and delete-expression on const reference and const pointer

C++ Much literature says const references cannot be used to modify their referents and const pointers cannot be used to modify their pointees. Then, why can they be deleted? const int& cirDynamic = *( new int(5) ); // ^ 'const int& cirDynamic = *(…
CodeBricks
  • 1,771
  • 3
  • 17
  • 37
0
votes
3 answers

How do you reproduce the behavior of const-pointers in Java?

I have a singleton class containing a bunch of control data that needs to be kept synchronized with the rest of my application. As a result, there are many times which I want another class to be able to read the information but not modify it. …
-1
votes
1 answer

C++ const pointers weird behaviour

Class C { struct Something { string s; // Junk. } // map from some string to something. map map; // Some more code: const Something *Lookup(string k) const { const something *l = SomeLookUpFunction(); cout <<…
dhruv
  • 19
  • 5
-1
votes
1 answer

Type conversions of a void pointer for pointer arithmetics

For using pointer arithmetics the type of a void pointer is converted multiple times. The vector containing the data comes from an external source and returns a void pointer to access its data. Furthermore, the stride is also given by the external…
Roi Danton
  • 7,933
  • 6
  • 68
  • 80
1 2
3