dereference

ptr->hello(); /* VERSUS */ (*ptr).hello();

岁酱吖の 提交于 2019-12-17 10:09:27
问题 I was learning about C++ pointers and the -> operator seemed strange to me. Instead of ptr->hello(); one could write (*ptr).hello(); because it also seems to work, so I thought the former is just a more convenient way. Is that the case or is there any difference? 回答1: The -> operator is just syntactic sugar because (*ptr).hello() is a PITA to type. In terms of the instructions generated at the ASM level, there's no difference. In fact, in some languages (D comes to mind), the compiler figures

Why does printing a pointer print the same thing as printing the dereferenced pointer?

本小妞迷上赌 提交于 2019-12-17 07:43:32
问题 From the Rust guide: To dereference (get the value being referred to rather than the reference itself) y , we use the asterisk ( * ) So I did it: fn main() { let x = 1; let ptr_y = &x; println!("x: {}, ptr_y: {}", x, *ptr_y); } This gives me the same results (x=1; y=1) even without an explicit dereference: fn main() { let x = 1; let ptr_y = &x; println!("x: {}, ptr_y: {}", x, ptr_y); } Why? Shouldn't ptr_y print the memory address and *ptr_y print 1? Is there some kind of auto-dereference or

Why does printing a pointer print the same thing as printing the dereferenced pointer?

佐手、 提交于 2019-12-17 07:43:06
问题 From the Rust guide: To dereference (get the value being referred to rather than the reference itself) y , we use the asterisk ( * ) So I did it: fn main() { let x = 1; let ptr_y = &x; println!("x: {}, ptr_y: {}", x, *ptr_y); } This gives me the same results (x=1; y=1) even without an explicit dereference: fn main() { let x = 1; let ptr_y = &x; println!("x: {}, ptr_y: {}", x, ptr_y); } Why? Shouldn't ptr_y print the memory address and *ptr_y print 1? Is there some kind of auto-dereference or

what is return type of assignment operator?

て烟熏妆下的殇ゞ 提交于 2019-12-17 06:38:16
问题 I am just starting C++. I am a bit confused about the return type of assignment and dereference operator. I am following the book C++ Primer. At various occasions, the author says that the return type of assignment operator is reference to the type of left hand operand but later on, he says that the return type is the type of the left hand operand. I have referred C++11 Standard Sec. 5.17, where the return type is described as "lvalue referring to left hand operand". Similarly, I can't figure

Vector iterator not dereferencable error when trying to push_back()

时光怂恿深爱的人放手 提交于 2019-12-13 22:32:31
问题 I have a problem when my application crashes with this error message from VS: "Debug assertion failed! (...) Expression: vector iterator not dereferencable". The thing is, it happens during using vector's push_back. Here is the code. It is my BigInt library, that I decided to implement as an exercise. The bug is hidden in my TestBigInt class, that I created to (surprisingly) test BigInt. The code is admittedly quite long, but I narrowed the bug to a single piece of that. This is the input I

Looks like double type variables have no methods. Something wrong with Java or NetBeans?

拥有回忆 提交于 2019-12-13 17:39:36
问题 According to Oracle I should be able to apply methods like .intValue() and .compareTo() to doubles but when I write dbl.toString() in NetBeans, for example, the IDE tells me that doubles can't be dereferenced. I can't even cast them to Integers in the form (Integer) dbl ! I have JDK 1.6 and NetBeans 6.9.1. What's the problem here? 回答1: The problem is your understanding of objects vs. primitives. More than anything else, you just need to recognize that the capitalized names are object classes

C: Accessing the second argv via a pointer

别等时光非礼了梦想. 提交于 2019-12-13 17:25:09
问题 As I'm quite new to C, there's something I don't yet get about pointers. I'd like to check wether a command line argument is integer or not, but in a separate function, so that I pass in the pointer of the argv array. int main(int argc, char* argv[]){ if(check(argv)){ // Do stuff to argv[1] } } int check(char* p){ // Test wether p+1 is int return 1; } I have tried several things mostly resulting in weird printf's (when printing the dereferenced pointer to test the value). int i = atoi(argv[1]

Cannot increment the value of a dereferenced pointer

谁都会走 提交于 2019-12-13 05:58:22
问题 I seem to have a problem with a simple program that is supposed to count various character types in a file. It always prints zeroes even though the file is not empty at all. I think it has something to do with pointers, could be wrong. I would also like to know if initializing variables is necessary in this case? // fun.h void count_char(FILE *f, unsigned *newl, unsigned *let, unsigned *num, unsigned *spec_char); // main.c #include <stdio.h> #include "fun.h" int main() { unsigned newline = 0,

Dreamweaver PHP array dereferencing

孤者浪人 提交于 2019-12-13 04:25:55
问题 I just installed PHP 5.4 and now that it supports array dereferencing I want to use that in my projects. Problem is that I'm working with Dreamweaver (CS6) and it gives me a syntax error for using the array brackets after the function parantheses. Is there any way to mess around with Dreamweaver's syntax support (or maybe just tuning the syntax highlighting in the configuration/CodeColoring directory may be enough)? 回答1: I would suggest to download another Editor if you work with PHP. Some

Oracle PL/SQL: How to DEREF from a VARRAY of REFs?

早过忘川 提交于 2019-12-12 21:41:05
问题 I'm new to Oracle Objects and I have a problem. I don't know how to dereference an item from a VARRAY of REFs. Below is some source code that reproduces the problem that I have. The error is: PLS-00306: Wrong number or types of arguments in call to 'DEREF' DROP TYPE LOC FORCE / DROP TYPE LIST_LOC FORCE / DROP TYPE PIZ FORCE / CREATE OR REPLACE TYPE LOC AS OBJECT( NAME VARCHAR2(30), MEMBER FUNCTION GET_NAME RETURN VARCHAR2 ) / CREATE OR REPLACE TYPE BODY LOC AS MEMBER FUNCTION GET_NAME RETURN