All Questions
22,965
questions
-11
votes
0
answers
63
views
What's the difference between 'ClassName* p' and 'ClassName p'? [duplicate]
Please explain to me the difference between Player p and Player* p.
Why should I write it like this:
Player *p = new Player(playwin, 1, 1, '#');
while (p->getmv() != 'x')
{
p->display();
...
-3
votes
0
answers
122
views
Are pointers smartly allocated? [duplicate]
While learning about pointers in Uni, They taught us that pointers are allocated memory for the address to be stored. And while I was messing around with pointers and null pointers.
I noticed this ...
1
vote
1
answer
128
views
Specify the type of a C++ pointer at runtime (generic pointer)
I am developing a simulation code written entirely in C++ where we use double precision for all computations. Now I want to make it configurable to use single precision if the user wants. The problem ...
0
votes
0
answers
38
views
A property of Python class returns an empty numpy array with pybind11
I adopted a project that was abandoned by it's original creator on GH: pybind11 bindings for whispercpp. I had to update Python version from 3.8 to 3.11.8 in CI and discovered that some of the test ...
0
votes
0
answers
63
views
Confusion regarding addresses and references in C++. What are the data types of addresses and references respectively? [duplicate]
I understood that the & operator is context dependent,
int var = 5;
int* ptr = &var;
In the above code, &var returns the address of var, then gives it to the pointer.
On the other hand
...
1
vote
1
answer
110
views
Arrays, Pointers and Memory addresses instances confusion in C++
I'm learning and playing a bit with pointers and memory addresses.
The thing is that I've tried doing some moves with instances inside arrays and getting their memory address, and I can't figure out ...
-3
votes
0
answers
106
views
Are pointer variables sometimes faster to initialize than reference variables?
Let's say just for acquiring the MEMORY-ADDRESS and VALUE of some variable. If the variable is "nested" in pointers like so:
int val = 10;
int *ptr1 = &val;
int *ptr2 = ptr1;
int *ptr3 =...
2
votes
2
answers
99
views
Circular linked list, destructor delete order causing seg-fault
Overview
I have a simple circularly linked list I was making for demonstration purposes (I know I should be using smart pointers, but this is a pedagogical exercise for memory and data structures).
...
-1
votes
1
answer
73
views
clang++ and g++ Compiler gives different output when printing char pointer [duplicate]
clang++ and g++ Compiler gives different output when printing char pointer
#include <iostream>
int
main(int argc, char** argv){
char a = 'a';
char* aptr = &a;
std::cout << aptr &...
1
vote
1
answer
76
views
Char array has different address when copied by pointer
What I'm trying to do is cheat the const-ness of the member variables of the class. So I have the following code:
"StringView.hh":
#pragma once
#include <cstring>
class StringView {
...
1
vote
0
answers
30
views
Typecast CUdeviceptr to uchar** in cuda access throws illegal memory access error 700 [duplicate]
We allocated the memory for CUdeviceptr for v1 object and type cast to uchar** type.
CUdeviceptr v1;
checkCudaResult(cuMemAlloc((CUdeviceptr*)&v1, 16));
checkCudaErrors(cudaMemset((void*)v1, 1, 16)...
0
votes
1
answer
61
views
How to Implement operator-> for a Custom UniquePtr Class in C++? [duplicate]
I am trying to write my own implementation of unique_ptr in C++, and here is my UniquePtr header file:
#include <iostream>
template <typename T>
class UniquePtr
{
T* ptr;
public:
...
0
votes
1
answer
75
views
What does the variable declaration `const int *__errno_location ()` inside this catch statement actually do?
While working on an exercise for my C++ class where we were working on Exception handling, I came across a puzzling issue. I initially had the following exception handler (Please don't roast the use ...
0
votes
1
answer
81
views
Transfer pointer from dll (c/c++) to python
I have a DLL written in C++ ( it can be rewritten in C ) and python code where I import the DLL with cdll.LoadLibrary(). Then I specify a function from DLL and it's agrument types. Then I call the ...
-1
votes
0
answers
25
views
Using Clion with Mac OS and I keep getting linker command failed with exit code 1 error, how do I fix it? [duplicate]
My code will not run no matter what I change, and I'm not sure what this error actually means. I just started this class so I have to use clion, which I am fairly new to. This is cloned from github to ...