How to fix this Intellisense error (XContainer::Element) - linq

The code bellow generates an error and I don't know how to fix it:
XElement^ root = XElement.Load("data.xml");
String^ location;
location = root->Element("location")->Value;
This is the error:
IntelliSense: no instance of function "System::Xml::Linq::XElement::Element" matches the argument list
argument types are: (const char [10])
object type is: System::Xml::Linq::XElement ^
How do I fix it?

XElement does have an Element method, but it takes an XName as its sole parameter, not a char array. Pass an XName instance instead of "location" and the error should disappear.

Related

libclang: how to get non-type template arguments from a CXType?

Given the following code to parse:
template <typename T, int N=3>
class Base {};
using BaseFloat1 = Base<float, 1>;
I can get the TypeAliasDecl from the last line, get the CXType from that, and the use clang_Type_getNumTemplateArguments() to see that there are two template arguments there, but the only option for retrieving the arguments is clang_Type_getTemplateArgumentAsType(), which obviously fails for the second, IntegerLiteral argument.
Is there any way to get the non-type template argument directly, other than inspecting the children of the TypeAliasDecl cursor?

A non well formed numeric value encountered in laravel

I am trying to add two variables together. I believe both contain an integer, but when I draw what is stored within $product->mileage, I receive the following error:
A non well formed numeric value encountered
$oilchange = $request->oilchange_at_kms;
$product = Product::find($request->product_id);
$mileage = $product->mileage; // Error within this variable, but it is an int
$total = $mileage + $oilchange;
How can I test this, or how can I find the problem in my code?
This error usually pops up when you try to add an integer with a string or some type of non numeric field.
You can test this by using the PHP gettype() method:
dump(gettype($product->mileage));
dd(gettype($oilchange));
If it turns out that one of these is a string (possibly from a form response), you can cast it to an int if you are certain that the value will always be an int.
$mileage = (int)$product->mileage;
Not really recommending this, as you should try to resolve the types within the variables first, but it may help you in testing.

How can I push back onto a vector an instance of a class in C++

Bear with me please, this is my first time posting. I have 3 classes. Class Suppliers has a set of Class Parent. Class Parent has a vector of Class location and Class location has data memebers. Ex (this is pseudo code, not my actual code. I've only shown this for simplicity sake):
Class Suppliers{
set<Parent> setter;
};
Class Parent{
vector<location> loc;
};
`
The following is the a constructor of the location class I created. I run into no problems until lines I hit the two lines with the iterators. I am trying to find a specific Parent and push back a new location onto the Parent 'loc' vector. So I pass in the iterator I've found previously as a reference. But as soon as I try to push back the new instance of my location class I get the following error.
data.cpp:139:33: error: passing 'const std::vector' as 'this' argument of 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = location; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::value_type = location]' discards qualifiers [-fpermissive]
The last line also gives an error that says I cannot alter a read-only object. I'm confused as to why this would be a read only object. I did some research and thought that I needed to add a copy constructor. However, that caused more problems than it solved. Any ideas?
location::location(set<Parent>::iterator &it, vector<string> v){
sup_id = v[0];
address1 = v[2];
address2 = v[3];
city = v[4];
state = v[5];
country = v[6];
zip = v[7];
((*it).loc).push_back(*this);
((*it).num)++;
}
The problem is that a set is sorted. If you'd be allowed to change an element through the iterator, it would basically mean that you could potentially invalidate the iterator and therefore since C++11, the iterator of a set is a constant bidirectional iterator and thereby has the same semantics as the set's const_iterator.
The solution, although slightly ugly, is to remove, modify and re-insert the element. There is a proposal to allow modification of the keys of associative containers, but I don't know if there is any progress in getting it standardized.

Using a variable in different forms

I have a variable called AUTO in Form1 and i want to use it in a form called RoomStack.
I declared this in RoomStack.h:
static Form1 ^FM = gcnew Form1();
(so afterwards i'll write something like FM->AUTO)
But the declaration is giving errors:
error C2143: syntax error : missing ';' before '^'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C3845: 'myUI::RoomStack::FM': only static data members can be initialized inside a ref class or value type
Note that i encountered this issue before and the same method worked.
I had a form called NewGame, it contained a variable that i wanted to use in Form1, so in Form1.h i declared:
static NewGame ^NG = gcnew NewGame();
and it compiled.
Why am i having errors now?
Form1.h should be included in RoomStack.h
i.e adding the following line in RoomStack.h solves the problem:
#include "Form1.h"

Problem with boost::intrusive_ptr

There is a struct which contain intrusive_ptr field:
struct BranchFeedback : boost::counted_base {
...
boost::intrusive_ptr<BPredState> theBPState;
};
There is another varibale which is defined as
std::vector< std::vector< BPredState > > theFetchState;
Now I have instantiated an object
BranchFeedback theFeedback;
and want to assign theFetchState to that field
theFeedback.theBPState = theFetchState[anIndex][!anOne];
However compiler says some errors
error: no match for ‘operator=’ in theFeedback.theBPState = .....
How can I fix that?
you're passing in a BPredState, but intrusive_ptr only supports operator= for pointers to the contained type (or other intrusive_ptrs)
so you could write theBPState = &(theFetchState[anIndex][!anOne]); or get an pointer or iterator to the element and use that instead.

Resources