dereference

Why can't I dereference a pointer to an object that's an array-element using the indirection operator?

百般思念 提交于 2021-02-16 09:48:53
问题 Is it not possible to dereference a pointer to an object that's stored in an array using the indirection(dereference) operator or am I doing something wrong? #include <iostream> class A { public: virtual void test() { std::cout << "A\n"; } }; class B : public A { public: void test() { std::cout << "B\n"; } }; int main() { A* v[2]; v[0] = new A(); v[1] = new B(); v[0]->test(); *(v[1]).test(); // Error! If the arrow operator is used instead // though, the code compiles without a problem. return

How to correctly dereference then delete a JavaScript Object?

人走茶凉 提交于 2021-02-07 12:01:46
问题 I would like to know the correct way to completely dereference a JavaScript Object from memory. To ensure it's deletion without it dangling in memory, and that the garbage collector removes the object. When I looked and this question Deleting Objects in JavaScript. It was explained that if you delete all the references of object, the GC will remove it from memory. I want to know how do I go about removing references from an object that has both methods and properties. Suppose you have and

C++ Dereferencing Arrays

心不动则不痛 提交于 2021-02-07 08:27:49
问题 I never read anything about dereferencing arrays like pointers and I believe it shouldn't work. But the following code does work using QT Creator and g++ 4.8: int ar[9]{1,2,3,4,5,6,7,8,9}; cout << *ar << endl; //prints the first element of ar Is it proper behavior or just the compiler fixing the code? 回答1: You cannot dereference an array, only a pointer. What's happening here is that an expression of array type, in most contexts, is implicitly converted to ("decays" to) a pointer to the first

C++ Dereferencing Arrays

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 08:24:02
问题 I never read anything about dereferencing arrays like pointers and I believe it shouldn't work. But the following code does work using QT Creator and g++ 4.8: int ar[9]{1,2,3,4,5,6,7,8,9}; cout << *ar << endl; //prints the first element of ar Is it proper behavior or just the compiler fixing the code? 回答1: You cannot dereference an array, only a pointer. What's happening here is that an expression of array type, in most contexts, is implicitly converted to ("decays" to) a pointer to the first

Better shared_ptr by distinct types for “ownership” and “reference”?

*爱你&永不变心* 提交于 2021-02-05 10:44:05
问题 I would like to use a pointer-like object Ownership<Type> m_foo for the owning object and handle Reference<Type> m_someFoo as a classical "pointer" in another context, whereas my Reference should know when the original object does not exist anymore (e.g. by returning nullptr) and it should furthermore be possible to prevent the original object from deletion for a small period of time (locking). I know that shared_ptr (Ownership) and weak_ptr (Reference) provide similar functionality. However,

C++: Is it posible to set the type of a void-pointer, variant-object or any-object in execution time?

孤者浪人 提交于 2021-01-28 23:22:14
问题 Void-pointer, variant-objects and any-objects are amazing because they can store many different types in the same variable. But I have a problem with them, I need to specify their type (creating and/or de-referencing them) in the execution time, is it possible? To be more clear, for example, as far I know, to create and de-reference them I have to do this: void* ptr = new int(8); variant<int, float> var = 8; any a = 8; ... cout << *(int*)ptr; cout << get<int>(var); cout << any_cast<int>(a);

NASM - is this the address, value?

风格不统一 提交于 2021-01-27 22:53:52
问题 TL;DR Is [memloc] referring to the value or the address? If it's referring to either, then why does it work both as a value and an address? (see code below, lines 4 and 5) Full question... Sorry for the long question. I'm confused by label dereferencing in NASM. Take this example: 01| section .text 02| ; exiting the program with exit code "15" 03| 04| mov [memloc], 15 ; move 15 into memloc 05| push [memloc] ; push memloc on stack 06| mov eax, 1 ; prepare exit syscall 07| call kernel ; invoke

dereferencing the whole Data of c_void_p not only the first byte

谁说我不能喝 提交于 2021-01-27 12:26:17
问题 i have a Question about Pythons ctypes and calling C functions bothering me for a couple days now. I'm working with Python 3.5 and ctypes to wrap a C .dll. I've got a C Function accepting a void ** as an output parameter. This should contain a Pointer to some 8 Bit RGB Data of a Image after the Call. foo(void ** bar) I declare my Python parameter and function call as following: >>bar = c_void_p() >>foo(byref(bar)) And try to recieve the Data: >>data = c_byte(bar.value) >>data.value 20 which

Rustlings thread exercise, why do I NOT dereference Mutex(Struct)?

六月ゝ 毕业季﹏ 提交于 2020-08-20 05:11:07
问题 I'm learning Rust and have no experience with threads. I'm going through the Rustlings course and I've solved the threads1.rs exercise, but I don't understand why my Mutex struct doesn't need to be dereferenced. use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; struct JobStatus { jobs_completed: u32, } fn main() { let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 })); let status_shared = Arc::clone(&status); thread::spawn(move || { for _ in 0..10 { thread:

Dereferencing one past the end pointer to array type

♀尐吖头ヾ 提交于 2020-06-23 07:08:08
问题 Is it well defined in c++ to dereference a one-past-the-end pointer to an array type? Consider the following code : #include <cassert> #include <iterator> int main() { // An array of ints int my_array[] = { 1, 2, 3 }; // Pointer to the array using array_ptr_t = int(*)[3]; array_ptr_t my_array_ptr = &my_array; // Pointer one-past-the-end of the array array_ptr_t my_past_end = my_array_ptr + 1; // Is this valid? auto is_this_valid = *my_past_end; // Seems to yield one-past-the-end of my_array