Related
Thomas B. Suppose you have a set of pointers (yes...): std::set<SomeType*> myTypeContainer;
Then suppose you want to search this collection from a const method of SomeType: bool SomeType::IsContainered() const
{
return myTypeContainer.find(this) != myType
Thomas B. Suppose you have a set of pointers (yes...): std::set<SomeType*> myTypeContainer;
Then suppose you want to search this collection from a const method of SomeType: bool SomeType::IsContainered() const
{
return myTypeContainer.find(this) != myType
Dean Why does the following work? #include <iostream>
using namespace std;
class PolyLine {
public:
PolyLine() = default;
PolyLine(PolyLine * ptr) {
std::cout << "Ctor called" << std::endl;
}
};
void function(const PolyLine& pt) {
}
int main() {
Barry In short, is it better to pass pointers by value or const reference? I wrote a simple function to explore: void foo(int* v) { std::cout << *v << endl; }
and void foo(int* const& v) { std::cout << *v << endl; }
I tried looking at the generated assembly,
csguy Isn't passing pointers by const reference for optimization? predecessor. bool testHelper(const TreeNode*& p, const TreeNode*& q) {
return false;
}
TreeNode* test(TreeNode* root, TreeNode* p, TreeNode* q) {
recursiveHelper(p, q);
}
mistake: Line
catch_0x16 When using 3D/2D graphics libraries, I often find myself passing a pointer to the render window to each drawable class that draws itself onto the canvas. However, every time I do this, I worry that by passing a pointer to the render window, the obje
Wengers I have the following code: #include <iostream>
int main(){
int v1 = 20;
int *p1 = &v1;
int **p2 = &p1;
return 0;
}
What I'm trying to do here is point one pointer to another and it works fine in this case. I make p1 point to a cons
Jon I'm playing with arrays and passing pointers by reference functions. Take the following code as an example: #include<iostream>
void test_fn(const int* const &i){
std::cout<<*i<<std::endl;
}
int main(){
int arr_1[5] {1, 3, 6, 4, 5};
int *int_p
Jon I'm playing with arrays and passing pointers by reference functions. Take the following code as an example: #include<iostream>
void test_fn(const int* const &i){
std::cout<<*i<<std::endl;
}
int main(){
int arr_1[5] {1, 3, 6, 4, 5};
int *int_p
Jon I'm playing with arrays and passing pointers by reference functions. Take the following code as an example: #include<iostream>
void test_fn(const int* const &i){
std::cout<<*i<<std::endl;
}
int main(){
int arr_1[5] {1, 3, 6, 4, 5};
int *int_p
Jon I'm playing with arrays and passing pointers by reference functions. Take the following code as an example: #include<iostream>
void test_fn(const int* const &i){
std::cout<<*i<<std::endl;
}
int main(){
int arr_1[5] {1, 3, 6, 4, 5};
int *int_p
innocent bystander Imagine the following simplified code: #include <iostream>
void foo(const int& x) { do_something_with(x); }
int main() { foo(42); return 0; }
(1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew
innocent bystander Imagine the following simplified code: #include <iostream>
void foo(const int& x) { do_something_with(x); }
int main() { foo(42); return 0; }
(1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew
innocent bystander Imagine the following simplified code: #include <iostream>
void foo(const int& x) { do_something_with(x); }
int main() { foo(42); return 0; }
(1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew
innocent bystander Imagine the following simplified code: #include <iostream>
void foo(const int& x) { do_something_with(x); }
int main() { foo(42); return 0; }
(1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew
innocent bystander Imagine the following simplified code: #include <iostream>
void foo(const int& x) { do_something_with(x); }
int main() { foo(42); return 0; }
(1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew
Steve Lorimer I have a class template Foowith the following member functions : bool contains(const T& item) const
I have instantiated this with a pointer type: Foo<Bar*>, leading me to expect that the member function will now have the following signature: boo
Taoist group I'm learning c++ and recently I read a book that recommends that you use references to const when possible (if the underlying object doesn't change). I have a question, you should pass a reference to a const pointer instead of a const pointer if p
Taoist group I'm learning c++ and recently I read a book that recommends that you use references to const when possible (if the underlying object doesn't change). I have a question, you should pass a reference to a const pointer instead of a const pointer if p
Taoist group I'm learning c++ and recently I read a book that recommends that you use references to const when possible (if the underlying object doesn't change). I have a question, you should pass a reference to a const pointer instead of a const pointer if p
Ultrasonic Banana In the function declaration below the second parameter, is a const pointer to const data. ti_rc_t ti_uart_write_buffer(const ti_uart_t uart, const uint8_t *const data, uint32_t len);
Below is sample code to call the function. Why is there on
bomb I want to form a struct from a const parameter passed to a function. Since the parameter is const, I guess the struct must also be const. However, it doesn't work with pointers. Compile the following code (MinGW 4.9.2 32bit) struct structType_t {
int
michalt38 Why with a pointer to const I can change the value of the variable pointed to by the pointer, but not with a const reference? int a = 10;
int * const ptr = &a;
(*ptr)++; // OK
const int & ref = a;
ref++; // error
Elias In your first example, you hav
Neeraj Bansal How to pass pointers const intin recursive calls . I'm calculating Fibonacci recursively using the following code format, but I'm getting an error: error: lvalue must be unary '&' operand** #include <iostream>
void fun(const int *n)
{
fu
Neeraj Bansal How to pass pointers const intin recursive calls . I'm calculating Fibonacci recursively using the following code format, but I'm getting an error: error: lvalue must be unary '&' operand** #include <iostream>
void fun(const int *n)
{
fu
Neeraj Bansal How to pass pointers const intin recursive calls . I'm calculating Fibonacci recursively using the following code format, but I'm getting an error: error: lvalue must be unary '&' operand** #include <iostream>
void fun(const int *n)
{
fu
Neeraj Bansal How to pass pointers const intin recursive calls . I'm calculating Fibonacci recursively using the following code format, but I'm getting an error: error: lvalue must be unary '&' operand** #include <iostream>
void fun(const int *n)
{
fu
Diapier In this code snippet, the large lookup table is easier to access using a pointer to the VLA : #pragma GCC diagnostic warning "-Wcast-qual"
char
lookup(int a, int b, int c, char const *raw, int x, int y, int z)
{
typedef char const (*DATA_PTR)[a][b
Diapier In this code snippet, the large lookup table is easier to access using a pointer to the VLA : #pragma GCC diagnostic warning "-Wcast-qual"
char
lookup(int a, int b, int c, char const *raw, int x, int y, int z)
{
typedef char const (*DATA_PTR)[a][b