Using a variable in different forms - visual-studio-2010

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"

Related

conditional instantiation of template class

I have a class MyClass<size_t, type>.
I would like to add conditional template instantiation using std::is_same and std::conditional.
However, both types for the first parameter are the same and are size_t.
As expected when MYSIZE1 and MYSIZE2 are the same, class<MYSIZE,int> will give an error.
How can I perform this conditional compilation considering that the only change is in the value of the template parameter?
template class MyClass<
std::conditional< (!std::is_same<MyClass<MYSIZE1,int>,
MyClass<MYSIZE2,int>
>::value),
MyClass<DUMMYSIZE,int>,
Myclass<MYSIZE1, int>
>::type,
int>;
This does not work obviously as conditional returns MyClass type.

Eigen Library: Compiler error when passing Block reference to templated function

I am getting a compilation error when trying to call templated functions with arguments that are Eigen references.
For example, consider the following simplified example:
template <typename derived>
inline void fcn(Eigen::MatrixBase<derived> &M){
// ...
M.template block<3,3>(0,0) = something here
// ...
}
// I get compiler errors when trying to call this function as follows:
Eigen::MatrixXd A(100,100);
// call the above function with a Block as an argument
fcn(A.block<9,6>(10,10));
The compiler complains that I am trying to instantiate a non-const reference with an object passed by value (if my undersdanding of the following is correct):
error: invalid initialization of non-const reference of type ‘Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, 9, 6, false> >&’ from an rvalue of type ‘Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, 9, 6, false> >’
If I try to declare the argument of fcn as const then I am getting an error when I try to modify it inside the function.
The only solution I've found to work to fix this issue is to declare the arument of the function to be a const &, and then to use const_cast to "remove the const qualifier" when accessing M inside the function.
But this is hacky and I makes the code extremely messy. Am I missing some obvious solution to this problem? Any help would be appreciated.
Thanks!
T
This is because in c++ you cannot bind a temporary object (here the proxy object returned by .block()) to a non-const reference. The solution is to name it:
auto A_block = A.block<9,6>(10,10);
fcn(A_block);

Where is this symbol defined/generated in the kernel source?

In drivers/base/firmware_class.c, there's a reference to dev_attr_loading in this struct:
static struct attribute *fw_dev_attrs[] = {
&dev_attr_loading.attr,
NULL
};
Where could that symbol be defined or generated? It doesn't seem to be anywhere in the source tree or generated files. I can't seem to find a macro that builds it either. I'm trying to think of more places or ways to look.
It's actually in the same file. It's created by a macro:
static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
The macro is defined in include/linux/device.h:
#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
The "_name" is what threw me in my search; I didn't realize that the underscore could be used in a macro that way.

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

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.

Can I use gcc visibility attributes on an enumeration?

I have the following enum:
__atttribute__((visibility ("default") )) enum MSG
{
OK,
FAIL,
};
When I compile, it gives me the warning:
warning: attribute ignored in declaration of ‘enum MSG’
warning: attribute for ‘enum MSG’ must follow the ‘enum’ keyword
When I put the attribute after the enum, I get the following errors:
warning: type attributes are honored only at type definition
error: use of enum ‘MSG’ without previous declaration
error: expected unqualified-id before ‘{’ token
Can anyone tell me how to fix this?
The visibility attribute applies to symbols like functions and variables. A definition of an enumeration type that doesn't contain a variable name doesn't create any symbols.
Enumeration type without a variable:
enum msg { OK, FAIL };
An enumeration variable:
enum msg message;
Enumeration type together with a variable:
enum msg { OK, FAIL } message;
In the first case, there's no symbol the visibility attribute could affect at all.
You can fix this by declaring the type of your enum like this:
enum class MSG : std::uint32_t __atttribute__((visibility ("default") ))
{
OK,
FAIL,
};
Though it seems like this is a bug in GCC that was fixed in versions 6+. Related SO post

Resources