boost::optional has changed an implicit function [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am using VS2008 and has just changed from boost 1.51 to 1.61. Unfortunately boost decided to change the boost::optional<T> and make the cast from optional to bool explicit i.e. the snippet below is not valid anymore
boost::optional<TYPE> optType;
TYPE t = default;
if (optType)
t = optType;
You must explicitly cast the optType to bool to make this work.
Even more unfortunate is the fact that this still compiles (with the wrong result ofc), and I am unable to detect where it is used. Does anyone know of any (even intrusive) methods to detect those places.
I tried to mark the implicit cast as deprecated in boosts 1.51 hpp-file but for some reason the compiler does not show any warnings.
The amount of code I have to look through is several hundred thousand rows that's why I need this.

In your particular snippet, you could simply write
boost::optional<TYPE> optType;
TYPE t = default;
if (optType)
t = true;
However, did you mean to get the TYPE value?
if (optType)
t = *optType;
You can also simply to
t = optType.get_value_or(default);

Related

Find when a particular place in memory is changed in c++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
Let's say I have an object MyObject and it has an attribute double MyObject::a. When I initialize a I set it to 0.05, but at some point when I run my code I notice that a is 1.something e-316, even though my code is never supposed to change its value. If I knew an exact place in memory that a occupies, is there a tool that will tell me when exactly this place is overwritten?
As others have already noted, you could use a debugger for this. Most reasonably recent debuggers have some capability to break when a value is written to a particular variable (e.g., Visual Studio calls this a "watchpoint" or "data breakpoint" (depending on what age of IDE you're looking at), if memory serves.
Depending on the situation, you might be able to get some useful information by changing your double to a const double:
const double value { 0.05 };
Then any code that tries to assign a new value to this variable simply won't compile.
If, however, the problem arises from some code doing an out of bounds write, rather than assigning to the value that's getting overwritten, this won't help find that.
gdb watchpoints
VS data breakpoints

namespace "Detours" has no member "uint8_t" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have been trying to create a dll program for a game called csgo. But my main problem is that it wont work until I have fixed this bug.
<namespace "Detours" has no member "uint8_t">
It happend right here:
oEndScene = (EndScene)Detours::X86::DetourFunction((Detours::uint8_t*)d3d9Device[42], (Detours::uint8_t*)hkEndScene);
Detour namespace doesn't define a uint8_t type (since it is from Microsoft, I think they'll name it something like USHORT). It is available in the STL in the global namespace. So to resolve this, dont specify where (which namespace) the type comes from,
oEndScene = (EndScene)Detours::X86::DetourFunction((uint8_t*)d3d9Device[42], (uint8_t*)hkEndScene);
And make sure to include stdint.h or inttypes.h header file to get the type.
Additional: Use reinterpret_cast<uint8_t*>() instead of (uint8_t*).
Add
#include <cstdint>
then remove the "Detours" part of "Detours::uint8_t". Just use the regular uint8_t, I don't think you need the wrapper.

Declaring non-intrinsic types with () after variable name has different behavior than without. i.e. std::map<int,char>x(); - what's with that? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a member variable declaration of:
std::map<int,char>x;
in my header file.
It compiles, but when I run my binary I get a segfault in the initialization of the class, before I even get into the constructor.
If I change the declaration to std::map<int,char>x(); -i.e. I just added a () after the variable name - it works fine, no segfault.
I can't give any more specific example than the above, but if anyone has experience with this I'd be interested to know what's going on.
Compiler version is gcc version 4.8.5
target is x86_64-redhat-linux
I realize this is fairly nonspecific but I'm only looking for a general answer.
Thanks.
This is the most vexing parse, as coined by Scott Meyers.
In the standard, look up Ambiguity resolution [stmt.ambig].
As for the segfault, you will need to provide the code (see MRE) to help you with that.

Is it possible to create temp structs/classes with initializer lists? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
It looks like a very basic question that should have an explicit googlable answer, but I wasn't able to find it so far. It seems like the answer is no, but I wanted to make sure.
What I mean is comething like this:
struct A { int a,b; };
void foo(const A&); // just some function
foo(A{1,2}); // doesn't work, but it was a long shot
foo(A({1,2})); // looks like it could have worked, but it doesn't
foo(A(std::initializer_list<int>({1,2}))); // ugly and doesn't work either anyway
Update:
option 2 actually works (as well as an even a simpler foo({1,2})), but only in vs2013, not in 2012.
Update #2: come on, was it necessary to downvote it so hard? It's still useful to know that it only works starting with vs2013.
Even easier than that. Behold the power of uniform initialization:
foo({1,2});

size_t redefined in calcstar [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I need to use calcstar that is math expression evaluator...
I just simply include calcstar.h file and it include everything else
#include "calcstar.h"
but when I try to compile my code i get this error:
size_t redefined
This error appears inside calcstar's own files...but the point is that this library is published online so I assume it is tested and doesn't have a bug...
What is the problem? Am I doing something wrong?
I really need a mathematical expression evaluator for my project.
CalcStar, assuming you got it from here, was apparently developed using Visual Studio 2008 (the download file name is CalcStarApp_VS2008_03202014.zip.).
One of the quirks of Visual Studio is that it allows redefinition of typedefs. Other compilers (like the one you appear to be using) do not.
You'll need to modify code appropriately.