Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
90 views

Reference on size 1 std vector from coefficient reference

Let's say we have a class X { private: std::vector<double> & values_; public: X(std::vector<double> & values) : values_(values) {} }; and that I want to create a class Y ...
11house's user avatar
  • 147
1 vote
1 answer
127 views

c++ undefined behavior of a reference to a base class

Please see my code. I have a base class "System" and a derived class "AdvancedSystem". When accessing the base class reference the output is undefined and random, and i have no ...
Miroslav Krajcir's user avatar
0 votes
1 answer
70 views

Const-correctness with getters of vector of non-pointers [duplicate]

I have a quick question regarding const-correctness for getters of vector of non-pointers. Basically, I have this class with a non-const getter and a const getter for m_Vertices: class Mesh { public: ...
Anthony Blanchette-Potvin's user avatar
0 votes
0 answers
55 views

How can I avoid nested vectors and self referencing structs?

I have the following problem to which I would like to find a Rust-idiomatic solution. The "step 0" of what I want to do is the following struct Point { x: f32, y: f32 } struct ...
MaPo's user avatar
  • 683
-1 votes
1 answer
86 views

Not able to add pointer to a vector in C++

I am trying to implement a grid system to detect colission between tanks in a game. My goal is to have around 40 cells which all have a vector with tank pointers. The tank should be in the right grid ...
Bas van der Veen's user avatar
-2 votes
1 answer
81 views

C++ Inheritance and passing vector references

Given the following code compiles and runs with no error class A { public: std::vector<int> i; void add(std::vector<int> &v) { i = v; } }; class B { public: B(A &a, std::...
mjkpolo's user avatar
  • 17
0 votes
1 answer
167 views

Reference to vector as class member

I tried to pass a vector as a class member by reference but I seem to have passed it by value. So I am making a class that has a function that can change the position of an element in a vector. The ...
b23's user avatar
  • 25
0 votes
1 answer
61 views

C++ vector not saving the parent of an object

Suppose I Have class A like this class A { public:int num; public:A* parent; A(){}; A::A (const A &s) { this->num = s.num; } }; Inside the main function I ...
geon_is_here's user avatar
2 votes
1 answer
481 views

How to get mutable reference to object inside vec inside a struct in rust?

I have a very basic problem in a rust relating to mutability of objects inside a vector. I have a need to get a mutable reference to an object from within a method of the struct as follows: struct ...
The amateur programmer's user avatar
0 votes
0 answers
115 views

I made function that returns vector of struct via reference. How to access its members w/o making a copy?

I'd like to print members of structure from static vector created inside a function. It might sound convoluted, so lets bring an example. struct Person { std::string name{}; int age{}; }; std::...
kvrier's user avatar
  • 23
0 votes
1 answer
442 views

C++ Undefined referenc to giv an vector<vector <char>> to an function [duplicate]

i have this complex error respectively it looks complex. I think I have a mistake at may transfer parameters. But I don't know what is the mistake. At the web I found this syntax and dont understand ...
Käsekuchen's user avatar
0 votes
1 answer
1k views

Proper way to share references to Vec between threads

I am new to rust and I am attempting to create a Vec that will live on the main thread, and pass a reference to another thread, which then pushes members onto the vector, for the main thread to use. ...
fudgeBreadstein's user avatar
1 vote
0 answers
13 views

How do I pass a reference to a class object from a range based for loop to a function argument?

I have my parser checking through a user input string, and comparing each individual word to an item or room name. These items and rooms are stored as class objects in a vector. I want to be sure that ...
Listless_Dreadnaught's user avatar
0 votes
1 answer
158 views

How I can create a reference of type std::vector<A>& from std::vector<B> where B is a class inherited from A

Project Structure I have a project structure like this : myProject ├── myLib │ ├── DataStructures.hpp/cpp │ └── DeviceManager.hpp/cpp └── QtDeviceView.hpp/cpp myLib/Datastructures: struct Device { ...
iElden's user avatar
  • 1,280
0 votes
0 answers
185 views

C++ const-reference loop over a vector containing map

#include <iostream> #include <vector> #include <string> #include <map> #include <unordered_map> #include <any> using namespace std; using MapAny = std::...
Huy Le's user avatar
  • 1,708

15 30 50 per page
1
2 3 4 5
20