Error C2102: '&' requires l-value, VS2019. How to fix? - c++

I am using DirectX 11 and trying to load variables locally in scope using XMLoadFloat4. I am doing a lot of it and names are pretty long so I don't want to create bunch of local variables, however with code like this:
XMStoreFloat4(&vertices[0].normal, XMVector3Cross(
XMLoadFloat4(&(vertices[2].position - vertices[0].position)),
XMLoadFloat4(&(vertices[0].position - vertices[1].position))
));
I'm getting C2102. Do you know elegant way to create reference in place like this?

You can work around this issue for now by disabling /permissive- by changing "Conformance Mode" to "No" in the C/C++ -> Language project settings.

Do you know elegant way to create reference in place like this?
The function expects pointers and you're trying to pass the address of temporaries which isn't allowed. Just store the temporary results in variables and pass the addresses to those:
auto a = vertices[2].position - vertices[0].position;
auto b = vertices[0].position - vertices[1].position;
XMStoreFloat4(
&vertices[0].normal,
XMVector3Cross(
XMLoadFloat4(&a),
XMLoadFloat4(&b)
)
);

Related

glBindTexture - returns argument error

I am working on augmented reality project. So the user should use the Webcam, and to see the captured video with a cube drawn on that frame.
And this is where I get stuck , when I try to use glBindTexture(GL_TEXTURE_2D,texture_background) method, I get error:
(
ArgumentError: argument 2: : wrong type
GLUT Display callback with (),{} failed: returning None argument 2: : wrong type
)
I am completely stuck, have no idea what to do . The project is done in Python 2.7 , am using opencv and PyOpenGl 3.1.0.
You can find code on this link :click here
Thanks in advance.
Interesting error! So I played around with your source code (by the way in the future you should probably just add the code directly to your question instead of as a separate link), and the issue is actually just one of variable scope, not glut or opengl usage. The problem is your texture_background variable does not exist within the scope of the _draw_scene() function. To verify this, simply try calling print texture_background in your _draw_scene() function and you will find it returns None rather than the desired integer texture identifier.
The simple hack-y solution is to just call global texture_background before using it within your _handle_input() function. You will also need to define texture_background = None in the main scope of your program (underneath your ##FOR CUBE FROM OPENGL comment). The same global comment applies for x_axis and z_axis.
That being said, that solution is not really that great. The rigid structure required by GLUT with all of these predefined glut* functions makes it hard to structure code the way you might want to in terms of initializing your app. I would suggest, if you are not forced to use GLUT, to use a more flexible alternative, such as pygame, pysdl2 or pyqt, to create your context instead.

queryExecute ColdFusion syntax vs Railo/Lucee syntax

I have a bunch of code that has been written against a Railo server. We are now trying to move some of that code over to a CF11 box and a Lucee box.
I have been using queryExecute like this:
rt = queryExecute(
sql = 'select *
from translation
where translationID = :translationID
and translatedStr = :translatedStr'
, params = {translationID: arguments.translationID
, translatedStr: arguments.translatedStr}
, options= {datasource: application.ds}
);
I was under the impression that the syntax was the same on CF11 but I am getting an error :
Parameter validation error for the QUERYEXECUTE function.
A built-in ColdFusion function cannot accept an assignment statement as a parameter,
although it can accept expressions. For example, QUERYEXECUTE(d=a*b) is not acceptable.
The above executeQuery works fine on Lucee. I am going to need to go through the whole code base and make it work on both CF11 AND on Lucee.
Can someone, who is more familiar with ACF, tell me what is the best way to do this. It appears that ACF is having trouble with the param names. If I remove sql = and params = that takes away some of the problem, although I like the readability of having them named. Also it appears that ACF doesn't like translationID: arguments.translationID and wants me to change it too translationID = arguments.translationID. I just want to make sure that there isn't something I am missing before I go through the time consuming process of making all the changes.
Pretty sure your parameters need to be in the form of a structure to include the value (and query param if you so choose).
Try this:
rt = queryExecute(
"select *
from translation
where translationID = :translationID
and translatedStr = :translatedStr",
{
translationID: {value: arguments.translationID},
translatedStr: {value: arguments.translatedStr}
},
{datasource: application.ds}
);
Well the error message is pretty clear, isn't it?
A built-in ColdFusion function cannot accept an assignment statement
as a parameter, although it can accept expressions. For example,
QUERYEXECUTE(d=a*b) is not acceptable.
And you have this:
queryExecute(
name = value
, name = value
, name= value
)
Which the error message says isn't allowed.
You just need to get rid of the names of your args. In-built CFML functions don't work like that. It's a compat bug in Lucee that it does support this.

Qt ActiveX dynamicCall: bad parameter count

I am trying to use an ActiveX control in my program.
QAxWidget* mAX = new QAxWidget();
mAX->setControl("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}");
I know that there is a function:
put_ChannelType(long newValue)
But when I try to execute it:
mAX->dynamicCall("put_ChannelType(long)",2);
mAX->dynamicCall("put_ChannelType(int)",2);
mAX->dynamicCall("put_ChannelType(long)",QVariant(2));
mAX->dynamicCall("put_ChannelType(int)",QVariant(2));
I get:
QAxBase: Error calling IDispatch member put_ChannelType: Bad parameter count
Any idea what is going wrong ?
EDIT:
Weird thing is if I call
mAX->dynamicCall("put_ChannelType()");
I do not get any error message...
EDIT 2:
This also fails (as Constantin suggested)
QList<QVariant> varlist;
varlist << (int)1;
mAX->dynamicCall("put_ChannelType(int)",varlist);
Got this solved using the generateDocumentation() function.
I was using this ActiveX control in another application, but an MFC one.
It seems the function names I was referring to (which were in a machine generated IDispatch wrapper class created by VS) were not the same as the ones Qt listed.
i.e. put_ChannelType is actually SetChannelType...
Maybe this is just a version issue ?
Anyways, important part is knowing that generateDocumentation() can list you all the functions you can call with dynamicCall.
Is it OK?
mAX->dynamicCall("put_ChannelType(const QVariant &)", (long)2);

Return value of a function in Visual studio

HI,
I am very much new to using Visual studio.
I am trying to debug an application.
where i came across a statement like below:
double tmp =
myPart->bat_qty() * timeFactor / myPart->AUB() * myPart->UCost * myAIM->param->myAnalysisParams->wd_year;
in VS when put the cursor at
timeFactor
myPart->UCost
myAIM->param->myAnalysisParams->wd_year
it shows the corresponding values.But Not of the values returned by
myPart->bat_qty()
myPart->AUB()
what is the easiest way to find the values returned by those functions.
Apologies if this appears to be a cliche kind of a query.But i am completely new to VS.
I need a better way to find the values returned without editing the files for storing the values in some temporary variables.i mean i sould not edit the files.
In VS 2010 you can put the breakpoint at the function call site and activate the "Autos" Window (if the Autos window is not visible you can make it visible from Debug -> Windows -> Autos Ctrl + Alt + V, A). In the Autos Window after you step over the function call (F10) you will see something in the lines of:
Name Value Type
[Func] Returned [Return Value] [Return Type]
where [Return Value] and [Return Type] are the appropriate return value and type for your function named [Func].
I hope this helps.
This has the advantage that you do not have to edit the code. The disadvantage I see is that if the returned type is complex you cannot expand it and inspect its attributes like you can do if you assign the return value to an automatic variable. However for simple structs the return value is expanded to something like this: {var1=[val1], var2=[val2]...} where var1, var2 are the attributes of the struct.
As far as I know the Autos Window is there (and did the same thing) back in VS 6.0 so this applies to VS 2005 too I guess (someone asked about VS 2005 too).
The quickest way is just to enter myPart->bat_qty() in the Immediate window. This way you don't need to change the code.
Assign them to a temporary, like this :
const double bat_qty_val = myPart->bat_qty();
const double AUB_val = myPart->AUB();
then use those in the equation instead of calling functions.
Off the top of my head, and Im sure there would be a more elegant way, but you could assign the return values of bat_qty() and AUB() to a temporary variable and watch them in the debugger.

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}