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

All Questions

Tagged with
-1 votes
0 answers
59 views

Why is constructor called, not overloaded operator=? [duplicate]

In the following code (also here: godbolt) Why is the constructor for myParam called in the assignment in main() and not the operator= overload? What can I do to force the assignment? Thanks! #include ...
Paul Sheppard's user avatar
-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(); ...
Иванов Леонид's user avatar
1 vote
1 answer
80 views

How do I use std::reference_wrapper to store the reference in an std::unordered_map?

I'm trying to learn the use of std::reference_wrapper and std::ref and the use cases of it. Here is a sample code I wrote. Please help me solve the compilation error. And it would be great if you can ...
Aman Kumar's user avatar
-1 votes
1 answer
58 views

How to loop through function and value of different class in c++ [duplicate]

So I am trying to basically do a* on a task planner, coz action typically have cost(risk, time, resources spent etc) and reward(effects) so I want to put it as an a* problem but for that I made each ...
Morris's user avatar
  • 1
0 votes
0 answers
71 views

In C++, when is it better to use a class with a state and an "execute" method, vs just a function? [closed]

My question is about code design in general, but consider the specific context of a numerical integration tool. Option 1: a class with a state, setters, accessors, and an execute method. class ...
josh_eime's user avatar
-2 votes
0 answers
80 views

Are there objects for primitive data types? [duplicate]

If the object represents a data type, is the variable for a primitive data type like an integer also an object representing this type, or do objects not represent primitive data types? // Let's assume ...
Ahmed Hamed's user avatar
1 vote
0 answers
47 views

How am i able to change constant class member? [duplicate]

I came up with the way to change members of constant class and i don't have an explanation for it. I came up with this example of code: #include <iostream> class Cool_class { public: int ...
Bulat Motigullin's user avatar
2 votes
1 answer
175 views

Explicit this member function use accepted by msvc but rejected by clang and gcc

I wrote the following program that compiles with msvc but rejected by clang and gcc. It uses explicit object member function. Demo. #include <iostream> struct C{ int f(this int); }; ...
Alan's user avatar
  • 1,118
-3 votes
2 answers
60 views

How can i select one of declared structure and make alias? [closed]

enum class Color { RED, BLACK }; enum class TreeModel { AVL, RED_BACK, SPLAY } struct BasicNode { BasicNode* left; BasicNode* right; BasicNode* parent; }; struct SplayNode : BasicNode { ...
vansergh's user avatar
0 votes
2 answers
54 views

class keyword for UPROPERTY()

I'm new to UnrealEngine and studying C++ development in scope of games. For now I read a tutorial where I should create a AMyPawn and UPawnMovementComponent to attach it then. Here is the definition ...
fyrsti's user avatar
  • 1
0 votes
1 answer
84 views

Type conversion in user defined class in c++

I made a matrix class in c++ namespace LinAlg { template <typename T> class Matrix { public: Matrix(); Matrix(const uint64_t &rows, const uint64_t &cols); template <typename P&...
Vedant Yadav's user avatar
-7 votes
1 answer
93 views

can anyone tell me how can I create multiple objects using vector without specifying the length of vector

I tried to do it using the vector<string> and iterating through it to create the object but while assigning them value i am getting error #include <iostream> #include <string> #...
shishi's user avatar
  • 1
-1 votes
0 answers
39 views

How to make a C++ struct that can have multiple independent static variables for each object of the struct? [duplicate]

I'm currently working on a Predator/Prey simulation in C++, and I'd like to keep track of certain stats (number born, number alive, and number died, specifically) for each one of various types (Animal,...
GorgeGrouse's user avatar
-1 votes
1 answer
67 views

How to use a non-static class member on all files?

Title. I need to access a class member that has to be non-static from another file. Example: // a.cpp #include "h.h" int main() { B num1(1); B num2(2); return 0; } // b....
MinersHaven's user avatar
1 vote
1 answer
45 views

c++ changing the data within the object, it returns to the original state [duplicate]

I am trying to develop a trade simulation for practical purposes. At the end of the code, I see that the values within the object have changed, but when it returns, it continues with the initial data. ...
Umut Altındağ's user avatar

15 30 50 per page
1
2 3 4 5
1062