Menu
  • HOME
  • TAGS

Pass an array of class objects as const to a function to prevent any modification of the class objects

c++,const,pass-by-pointer

foo_objects_ptr + i has the same type as foo_objects_ptr, so that is also a const pointer. So foo_objects_ptr[i] is const for all i....

Why do these blocks of code behave differently?

perl,pass-by-reference,subroutine,pass-by-value,pass-by-pointer

In the first example, you use the reference to get the array and then you modify that. There is only one array and you change it. In the second example, you use the reference to get the array, then you copy the content of the array into a second array,...

Is Swift Pass By Value or Pass By Reference

swift,pass-by-reference,pass-by-value,pass-by-pointer

Types of Things in Swift The rule is: Class instances are reference types (i.e. your reference to a class instance is effectively a pointer) Functions are reference types Everything else is a value type; "everything else" simply means instances of structs and instances of enums, because that's all there is...

Does D pass value by copy?

d,pass-by-value,pass-by-pointer

Classes in D use reference semantics so b points to the same object as a. structs, on the other hand, use value semantics so... auto a = mystruct(); auto b = a; ...would refer to distinct objects....

What operators do I have to overload to see all operations when passing an object to a function?

c++,operator-overloading,pass-by-reference,pass-by-value,pass-by-pointer

In C++11, you should add rvalue reference: A(A&&); void operator=(A&& a ); ...

C++ Passing by pointer and passing by reference

c++,parameter-passing,pass-by-reference,pass-by-pointer

Use: void assignment(int* (&x)[5]) ... edit: for the comment "if the length... wasn't standard...", you can use a template: template<int N> void assignment(int* (&x)[N]) ... The compiler will automatically deduce N....

What is the correct way to receive a pointer to a C-style string as an argument and be able to allocate memory or modify it?

c++,pass-by-reference,cstring,pass-by-pointer

The standard C way to do this, is to pass two pointers to the function: int getName(char** name_out, size_t* size_out); This has several advantages: The caller is free to preallocate memory/reuse an allocation. The callee is free to adjust the allocation via realloc() (assuming that the C-style string is allocated...