Watch and expression must have a pointer - visual-c++

auto_ptr<MoistAir> ma(new MoistAir);
L1->setPabs(Pabs);
L1->setQm(qm2);
L1->setT(t1);
L1->setX(x1);
if ((L2->getQm() / L3->getQm()) > 1)
w = L3->getQm() / (A0 * 1.2);
else
w = L2->getQm() / (A0 * 1.2);
//This is a function i tried to add watch on
double MoistAir::getQm()
{
return Fqm;
}
I tries to add watch on the function in visual studio to get the result? Is it possible. Do i have to introduce a variable or step in to the function? I just want to mark the code as in C# and get value.
If i step in to then function i can see the result.

After some more reading/talking to person programming C/C++ told me how to do. maybe it's can help somebody else.
((L2)._Myptr)->getQm() 2.3999999756939365 double

In my case the object was a Shared_ptr, I used ((&Shared_PtrObj)->_Ptr)->objMethod(). This solved my issue and showed the exact output on watch window.

It seems that the variable is not getting any value. Try checking the return value of L3->getQm() by create a new variable and assigning it the result of L3->getQm().
I'm not very sure if your if-statement is correct, but in my experience, when I have two conditions in the same if-statement I usually use || or && depending on what I want.
Good luck with your app.

Related

I got this error in this function: Invalid operands 'float' and 'Vector2' in operator '!='

func move(motion):
if motion != Vector2():
target_angle = atan2(motion.x, motion.y) - PI/2
Skin.set_rot(target_angle)
I tried converting vectors to ints. I looked up this error and didnt understand fixes.
What does motion != Vector2() mean?
It is comparing two things to see if the are different:
motion a variable parameter of the function move which is Variant (it does not have a declared type).
Vector2() this is the default constructor of the Vector2 type. It should be equivalent to Vector2.ZERO or Vector2(0.0, 0.0).
Now, the error is telling you that you got a float, and that Godot does not know how to compare float and Vector2.
You might have expected that checking if a float is different from a Vector2 would return true (a float is different from a Vector2), but no, the comparison is an error. Yes, I tried. Otherwise the execution flow would enter the conditional and try to execute atan2(motion.x, motion.y) with a float and that would be error.
This means you need to ensure it is a Vector2 before comparing it with another Vector2.
You could have prevented getting a float here by declaring the type of the parameter:
func move(motion:Vector2):
if motion != Vector2():
target_angle = atan2(motion.x, motion.y) - PI/2
Skin.set_rot(target_angle)
And now it would give you an error where you are calling it with a float. Why or where are you calling it with a float? I don't know. Presumably if you are getting the error in runtime you can also find out by looking at the stack on the debugger panel when the error shows up. Otherwise, this is a sure way to find out.
By the way, aren't the parameters of atan2 backwards? Are you aware of motion.angle()?
Anyway, Bugfish is right that you can check if the type of motion is Vector2 in runtime, for example: typeof(motion) == TYPE_VECTOR2.
If I understand correctly you claim you did this: var motion = Vector2(). Well, something else happened somewhere, and we cannot find it for you. I presume you change the value of motion somewhere (that is the point of having a variable) perhaps set it to the return value of a function var motion = get_motion() or similar, and it sometimes returns a float...
Which, reminds me, you can also specify what your methods return. This method returns nothing (void):
func move(motion:Vector2) -> void:
if motion != Vector2():
target_angle = atan2(motion.x, motion.y) - PI/2
Skin.set_rot(target_angle)
And this one returns a Vector2:
func get_motion() -> Vector2:
return Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
Yes, GDScript has static types, use them!
Well it seems like your parameter motion does not contain a Vector2, but a float value. Where do you call the function and did you already check if the functions gets the parameter you wanted to pass it?
Also before using a vatiable with unknown type, You should check the type, before assuming it's an Vector.
One way would be to check it's type:
if typeof(motion) != TYPE_VECTOR2:
return

How to know if returning an l-value when using `FALLBACK`?

How can I know if I actually need to return an l-value when using FALLBACK?
I'm using return-rw but I'd like to only use return where possible. I want to track if I've actually modified %!attrs or have only just read the value when FALLBACK was called.
Or (alternate plan B) can I attach a callback or something similar to my %!attrs to monitor for changes?
class Foo {
has %.attrs;
submethod BUILD { %!attrs{'bar'} = 'bar' }
# multi method FALLBACK(Str:D $name, *#rest) {
# say 'read-only';
# return %!attrs{$name} if %!attrs«$name»:exists;
# }
multi method FALLBACK(Str:D $name, *#rest) {
say 'read-write';
return-rw %!attrs{$name} if %!attrs«$name»:exists;
}
}
my $foo = Foo.new;
say $foo.bar;
$foo.bar = 'baz';
say $foo.bar;
This feels a bit like a X-Y question, so let's simplify the example, and see if that answers helps in your decisions.
First of all: if you return the "value" of a non-existing key in a hash, you are in fact returning a container that will auto-vivify the key in the hash when assigned to:
my %hash;
sub get($key) { return-rw %hash{$key} }
get("foo") = 42;
dd %hash; # Hash %hash = {:foo(42)}
Please note that you need to use return-rw here to ensure the actual container is returned, rather than just the value in the container. Alternately, you can use the is raw trait, which allows you to just set the last value:
my %hash;
sub get($key) is raw { %hash{$key} }
get("foo") = 42;
dd %hash; # Hash %hash = {:foo(42)}
Note that you should not use return in that case, as that will still de-containerize again.
To get back to your question:
I want to track if I've actually modified %!attrs or have only just read the value when FALLBACK was called.
class Foo {
has %!attrs;
has %!unexpected;
method TWEAK() { %!attrs<bar> = 'bar' }
method FALLBACK(Str:D $name, *#rest) is raw {
if %!attrs{$name}:exists {
%!attrs{$name}
}
else {
%!unexpected{$name}++;
Any
}
}
}
This would either return the container found in the hash, or record the access to the unknown key and return an immutable Any.
Regarding plan B, recording changes: for that you could use a Proxy object for that.
Hope this helps in your quest.
Liz's answer is full of useful info and you've accepted it but I thought the following might still be of interest.
How to know if returning an l-value ... ?
Let's start by ignoring the FALLBACK clause.
You would have to test the value. To deal with Scalars, you must test the .VAR of the value. (For non-Scalar values the .VAR acts like a "no op".) I think (but don't quote me) that Scalar|Array|Hash covers all the l-value super-types:
my \value = 42; # Int is an l-value is False
my \l-value-one = $; # Scalar is an l-value is True
my \l-value-too = #; # Array is an l-value is True
say "{.VAR.^name} is an l-value is {.VAR ~~ Scalar|Array|Hash}"
for value, l-value-one, l-value-too
How to know if returning an l-value when using FALLBACK?
Adding "when using FALLBACK" makes no difference to the answer.
How can I know if I actually need to return an l-value ... ?
Again, let's start by ignoring the FALLBACK clause.
This is a completely different question than "How to know if returning an l-value ... ?". I think it's the core of your question.
Afaik, the answer is, you need to anticipate how the returned value will be used. If there's any chance it'll be used as an l-value, and you want that usage to work, then you need to return an l-value. The language/compiler can't (or at least doesn't) help you make that decision.
Consider some related scenarios:
my $baz := foo.bar;
... (100s of lines of code) ...
$baz = 42;
Unless the first line returns an l-value, the second line will fail.
But the situation is actually much more immediate than that:
routine-foo = 42;
routine-foo is evaluated first, in its entirety, before the lhs = rhs expression is evaluated.
Unless the compiler's resolution of the routine-foo call somehow incorporated the fact that the very next thing to happen would be that the lhs will be assigned to, then there would be no way for a singly or multiply dispatched routine-foo to know whether it can safely return an r-value or must return an l-value.
And the compiler's resolution does not incorporate that. Thus, for example:
multi term:<bar> is rw { ... }
multi term:<bar> { ... }
bar = 99; # Ambiguous call to 'term:<bar>(...)'
I can imagine this one day (N years from now) being solved by a combination of allowing = to be an overloadable operator, robust macros that allow overloading of = being available, and routine resolution being modified so the above ambiguous call could do something equivalent to resolving to the is rw multi. But I doubt it will actually come to pass even with N=10. Perhaps there is another way but I can't think of one at the moment.
How can I know if I actually need to return an l-value when using FALLBACK?
Again, adding "when using FALLBACK" makes no difference to the answer.
I want to track if I've actually modified %!attrs or have only just read the value when FALLBACK was called.
When FALLBACK is called it doesn't know what context it's being called in -- r-value or l-value. Any modification comes after it has already returned.
In other words, whatever solution you come up with will being nothing to do per se with FALLBACK (even if you have to use it to implement some other aspect of whatever it is you're trying to do).
(Even if it were, I suspect trying to solve it via FALLBACK itself would just make matters worse. One can imagine writing two FALLBACK multis, one with an is rw trait, but, as explained above, my imagination doesn't stretch to that making any difference any time soon, if ever, and could only happen if the above imaginary things happened (the macros etc.) and the compiler was also modified to pay attention to the two FALLBACK multi variants, and I'm not at all meaning to suggest that that even makes sense.)
Plan B
Or (alternate plan B) can I attach a callback or something similar to my %!attrs to monitor for changes?
As Lizmat notes, that's the realm of Proxys. And thus your next SO question... :)

How to convert a string into a variable name in MATLAB? [duplicate]

Let's assume that I want to create 10 variables which would look like this:
x1 = 1;
x2 = 2;
x3 = 3;
x4 = 4;
.
.
xi = i;
This is a simplified version of what I'm intending to do. Basically I just want so save code lines by creating these variables in an automated way. Is there the possibility to construct a variable name in Matlab? The pattern in my example would be ["x", num2str(i)]. But I cant find a way to create a variable with that name.
You can do it with eval but you really should not
eval(['x', num2str(i), ' = ', num2str(i)]); %//Not recommended
Rather use a cell array:
x{i} = i
I also strongly advise using a cell array or a struct for such cases. I think it will even give you some performance boost.
If you really need to do so Dan told how to. But I would also like to point to the genvarname function. It will make sure your string is a valid variable name.
EDIT: genvarname is part of core matlab and not of the statistics toolbox
for k=1:10
assignin('base', ['x' num2str(k)], k)
end
Although it is long overdue, i justed wanted to add another answer.
the function genvarname is exactly for these cases
and if you use it with a tmp structure array you do not need the eval cmd
the example 4 from this link is how to do it http://www.mathworks.co.uk/help/matlab/ref/genvarname.html
for k = 1:5
t = clock;
pause(uint8(rand * 10));
v = genvarname('time_elapsed', who);
eval([v ' = etime(clock,t)'])
end
all the best
eyal
If anyone else is interested, the correct syntax from Dan's answer would be:
eval(['x', num2str(i), ' = ', num2str(i)]);
My question already contained the wrong syntax, so it's my fault.
I needed something like this since you cannot reference structs (or cell arrays I presume) from workspace in Simulink blocks if you want to be able to change them during the simulation.
Anyway, for me this worked best
assignin('base',['string' 'parts'],values);

Porting from VS6 to VS2012: return values screwed up

While porting a VS6 project to VC++2012 environment, I'm experiencing a strange behavior...
Let's say I've the following
// double AreaIco = 75.0;
// double theApp.m_GlobalScale = 0.25;
double ToLong(double); // elsewhere defined
double result = ToLong(AreaIco * theApp.m_GlobalScale * theApp.m_GlobalScale);
What I find is that the ToLong function gets "0" as input parameter
This also happens if I try to introduce temporary variables:
double temp1 = AreaIco * theApp.m_GlobalScale;
double temp2 = temp1 * theApp.m_GlobalScale;
AreaIcoInScala = ToLong(temp2);
Both temp1 and temp2 evaluate to either 0 or a denormalized value.
However, trying to evaluate the expression in QuickWatch returns correct value.
Does anyone have any clue for such a behavior? I fear there's some ancient bug in the code, which has been covered since now by somethink in VS6...
Thanks anyone for support, anyway.
After some futher investigation, we found it was a problem with data structure alignment.
In VS options the Struct Member Alignment was set to 4 bytes, while a #pragma pack 2 was present in one of the source files.
Strange enough, everything worked under VS6, the porting to VS2012 made this issue come out.

assigning a string to a complex pointer

I'm trying to assign a string to an array defined like this
char *(*attributes)[][2]; as defined by a library I'm using.
I want to be able to put a string into attributes[i][0]
I think I'm just getting confused about the pointers, I'm getting errors saying invalid use of array with unspecified bounds.
The array of attributes is stored in a struct called info.
I've tried to access it as:
*(info->attributes)[i][0] = newAttributeName
which makes sense to me, but as I said, isn't working.
Any help would be greatly appreciated!
Since no one else is offering, I'd suggest:
char *attributesa[][2] = *attributes;
char *attributesb[2] = attributesa[0];
attributesb[0] = "Horsefeathers";
and then figure out how to turn that into one statement.
Here's the correct way, for future reference:
(*info->attributes)[i][0] = someString;
The trick is the parenthesis give precedence to info->attributes being dereferenced, because otherwise it will try to find [i][0] first.

Resources