When you pass a pointer by a non-const
reference, you are telling the compiler that you are going to modify that pointer’s value. Your code does not do that, but the compiler thinks that it does, or plans to do it in the future.
To fix this error, either declare x
constant
// This tells the compiler that you are not planning to modify the pointer // passed by reference void test(float * const &x){ *x = 1000; }
or make a variable to which you assign a pointer to nKByte
before calling test
:
float nKByte = 100.0; // If "test()" decides to modify `x`, the modification will be reflected in nKBytePtr float *nKBytePtr = &nKByte; test(nKBytePtr);
Related Posts:
- What are the differences between a pointer variable and a reference variable in C++?
- What does `*&` in a function declaration mean?
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Reference to non-static member function must be called
- C++ pass an array by reference
- Is C++ Array passed by reference or by pointer?
- Linker Error C++ “undefined reference ” [duplicate]
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- What exactly is nullptr?
- Are the C++ & and * operators inverses in all contexts?
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- How to fix a “invalid operands to binary expression” error?
- What is a dangling pointer?
- (->) arrow operator and (.) dot operator , class pointer
- Pass a vector by reference C++
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- how does the ampersand(&) sign work in c++?
- C++ – No matching member function for call to ‘push_back’
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Difference between const reference and normal parameter
- Pointer to incomplete class type is not allowed
- Passing a 2D array to a C++ function
- Is the practice of returning a C++ reference variable evil?
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- When should I use the new keyword in C++?
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- How to access the contents of a vector from a pointer to the vector in C++?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- What does int & mean
- C++: Expression must have a constant value when declaring array inside function
- Sorting Linked List C++ with pointers
- Delete 2D array C++
- Is the sizeof(some pointer) always equal to four?
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- Typedef function pointer?
- How to initialize a vector of pointers
- What is the use of intptr_t?
- Error: No instance of constructor matches the argument list
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- C++ – Assigning null to a std::string
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Why use pointers?
- C++ Return value, reference, const reference
- What’s the difference between * and & in C?
- How to create a vector of class objects in C++?
- Function stoi not declared
- C++ Array of pointers: delete or delete []?
- Why should I use a pointer rather than the object itself?
- Function stoi not declared
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- Is null reference possible?
- Initializing pointers in C++
- Why can’t I make a vector of references?
- Difference between function arguments declared with & and * in C++
- Difference between the int * i and int** i
- set head to NULL (‘NULL’ : undeclared identifier)
- What is a `char*`?
- clearing a vector of pointers [duplicate]
- C++ Swapping Pointers
- Meaning of *& and **& in C++
- Array of Linked Lists C++
- Differences between unique_ptr and shared_ptr
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- Graphics Library for C++
- ‘cout’ was not declared in this scope
- warning: ISO C++ forbids variable length array
- cin >> “no operator matches these operands”
- C++ Structure Initialization
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- Enum to String C++
- Random float number generation
- C++ terminate called without an active exception
- MinGW: “gcc is not recognized as an internal or external command”
- Convert Python program to C/C++ code?
- warning: control reaches end of non-void function [-Wreturn-type]
- Program received signal SIGSEGV, Segmentation fault
- Difference between ‘struct’ and ‘typedef struct’ in C++?
- Debug vs Release in CMake
- Cygwin Make bash command not found
- C++ Compiler Error C2280 “attempting to reference a deleted function” in Visual Studio 2013 and 2015
- Why I cannot cout a string?
- How do I return a char array from a function?
- Converting String to Cstring in C++
- creating dynamic array of string c++
- “No rule to make target ‘install'”… But Makefile exists
- How to determine the version of the C++ standard used by the compiler?
- Make / gcc cryptic error 2: how to have more information?
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization