Skip to main content

New answers tagged

4 votes
Accepted

Optimal way to share data between different classes

Let me restate your main issue first: you have a loosely structured Main class which has become too large over time, and now you are refactoring parts of it to classes A and B, to give the program ...
Doc Brown's user avatar
  • 210k
2 votes

Optimal way to share data between different classes

I would start by changing your perspective on the Main class. Treat this more as a composition root for your application. The Main class should be responsible for configuration and initializing ...
Greg Burghardt's user avatar
0 votes

Share Global Variable in DLL, feasible or naive?

In theory, you can achieve this in multiple ways. You can use a shared memory, via the file mapping API. You can have the state in a "master" process and the "slave" processes can ...
anon_user123456's user avatar
0 votes

How to make max-heap stable with counter and account for counter overflow?

I am not sure what the C++ standard says about heap stability but the implementation coming from SGI currently used by GCC appears to be stable from my reviewer point of view. I was looking into the ...
lano1106's user avatar
1 vote
Accepted

How to Handle Additional Parameters in State Transition for State Pattern in C++

The extra parameter will only make sense in a layer of the code where the class StateB "lives". Let me call this "application layer". Your state pattern implementation, especially ...
Doc Brown's user avatar
  • 210k
5 votes

Is the inability to find code by searching for a class name a reason to avoid using auto in c++ variable declarations?

It is true that code is being read and maintained more often than it is written. But that's one more reason to use auto ! auto to accelerate change propagation For the maintenance of code, auto has ...
Christophe's user avatar
  • 78.7k
4 votes

Is the inability to find code by searching for a class name a reason to avoid using auto in c++ variable declarations?

It depends on how clever your development software is. Searching for all uses of MyClass as text is easy. But some IDEs have the ability to search for MyClass as a symbol as well. That could be by ...
gnasher729's user avatar
6 votes

Is the inability to find code by searching for a class name a reason to avoid using auto in c++ variable declarations?

No, I don't think this is a valid reason to avoid all usage of auto in general. It may be a valid reason for certain cases (though both of your examples look somewhat debatable to me). Let me first ...
Doc Brown's user avatar
  • 210k
7 votes

Is the inability to find code by searching for a class name a reason to avoid using auto in c++ variable declarations?

It's certainly a valid reason. Whether that's enough of a reason to avoid auto in your situation - that depends on whether there are superior reasons for using it. Presumably you can find such ...
Kilian Foth's user avatar
4 votes

C++: Good approach to handle libxml2 resource management in a wrapper

#1 sounds good, your XMLNode just needs to distinguish between the cases where the node is in an XMLDocument, or not (_xmlNode struct has a doc field, I looked it up). When it is, don't free the node ...
Doc Brown's user avatar
  • 210k

Top 50 recent answers are included