Using map function to map to user options to specific function - c++

I am new to C++ and need some help with the following:
If i have no namespace this works fine as soon as i have this i get a error :
(active) E0109 expression preceding parentheses of apparent call must have (pointer-to-)
I am attaching a solution where i have implemented this code to show the error.
What i am tryng to achive is to use this map to call my menu options a user can select, it has a header file as well as the cpp implemtation file in it.
I have attached the source code with the error showing when trying to compile this.
I would greatly appreciate some help - sample attached done in visual studio Sample Code
https://www.dropbox.com/s/j5nkxabjah313wz/SampleMenu.zip?dl=0

Related

How can I set a stack panel's border color programmatically in C++ in WinUI3?

I am working on a project using WinUI 3 in C++, and I want to change the border color of a XAML control(e.g. stackpanel) according to some condition. I have tried search it online, but most of answers are in c#, and some in C++ I have tried but got no luck.
For example: ("StackPanel" is defined in the xaml )
StackPanel().BorderBrush(SolidColorBrush(ColorHelper::FromArgb(255, 255, 255, 255)));
Then the error would come up:
no instance of overloaded function matches the argument list
argument types are: (winrt::Windows::UI::Xaml::Media::SolidColorBrush)
object type is: winrt::Microsoft::UI::Xaml::Controls::StackPanel
And another one I tried in .cpp file:
StackPanel().BorderBrushProperty(SolidColorBrush(Colors::Black()));
the error is:
too many arguments in function call.
Why are these errors happening?
Could anyone help me on this? Or any suggestions?
Sample code would be great!
PS : I am still very new to WinUI 3 especially in C++ (there are not so much study material for C++)
I would be grateful for any help.
From what I'm seeing the actual error (as best as i can replicate what you're doing) is
Severity Code Description Project File Line Suppression State
Error C2664 'void Windows::UI::Xaml::Controls::StackPanel::BorderBrush::set(Windows::UI::Xaml::Media::Brush ^)': cannot convert argument 1 from 'Windows::UI::Xaml::Media::SolidColorBrush' to 'Windows::UI::Xaml::Media::Brush ^' App1 c:\repos\App1\MainPage.xaml.cpp 29
If you create your brush like this auto brush = ref new SolidColorBrush(...);
And pass it to the stackpanel like this stackpanel->BorderBrush = brush;
Your error should go away.
Obviously how you are getting your stack panel might be different from how i did, but the point is you should be able to just set it to the value as long as you have the value in the correct form a ref new object in this case, it would seem.

Visual Studio 2017: Ruleset won't execute

I want to define a custom set of rules to be checked at compile time. But it seems not to work.
Example:
I choose one rule directly and I'll get the expected warning.
But when I instead create a custom ruleset containing the exact same rule then I won't get the expected warning.
What could be wrong?
Edit:
void f(std::string& i) {
std::string s = i;
cout << s;
}
int main()
{
std::string s ("abc");
f(s);
}
This gives me the expected warning Warnung C26460 The reference argument 'i' for function 'f' can be marked as const (con.3). in the first case.
Even if I create a custom ruleset including all available rules, I won't get any warnings.
Here you see me selecting the custom ruleset:
Edit: The ruleset action must change one time to enable it.
When I create a new ruleset containing only the const-checks then I will get a .ruleset that does not work and look like this:
In the ruleset editor it looks like this:
When I then change its action from Warning to Error:
Then the .ruleset gets additional lines for each test case:
When I change the action back to warning it looks like this:
Now it is working as expected.
I've been able to reproduce your error with Visual Studio 2017. I don't know exactly what I changed (or if I changed anything at all), but I am able to see the code analysis warning you expect with a custom rule set.
Things I would try:
Double check the Error List window is visible and not hiding somewhere.
Open the rule set file, change the Action to Error and then back to Warning and save it. I wouldn't expect this to be the problem but it's one of the things I did and after which I started seeing the Error List window.

Glass Mapper t4 null or empty string

I'm trying to setup Glass Mapper to generate my Sitecore items. I've followed every tutorial I could find, but receive this error when attempting to generate the code:
"Loading the include file 'Helpers.tt' returned a null or empty string. The transformation will not be run."
A file is generated but repeats the word "ErrorGeneratingOutput" over and over.
Screenshots:
As well as what Ehab has suggested, you may also have to remove the empty line at the end of GlassV3Header.tt otherwise you will get a error:
An error occured while generating code for item '/sitecore/templates'.
T4 Template: D:\Project\XYZ\TDS.Master\Code Generation Templates\GlassV3Item.tt
Errors:
Compiling transformation: Invalid token 'this' in class, struct, or interface member declaration
Compiling transformation: Method must have a return type
Compiling transformation: Type expected
Crytic, but deleting the extra line solves the issue.
Have you tried to click the unblock button in the properties window of the file?

Visual C++ - Throwing unhandled exception from setting forms icon?

I can compile the solution with no errors, but when I'll try to run it, I get a crash window:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "<myformname>.resources" was corerctly embedded or linked into assembly "<myprojectname>" at compile time, or that all the satellite assemblies required are loaded and fully signed.
And after I press Break it throws me to the line:
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
If I comment this line out, everything works just fine, but my program doesn't have icon.
Anyone else had this problem? Found a solution? I couldn't find anything clear enough for me to understand, problem is really annoying me, only solution I found was to declare my form class before any other classes, but I don't even have any other classes in my solution?
I also have only one project in this solution, ms support said something about having multiple projects, which I don't have, so it was no use either.
Take a look here :
http://www.mztools.com/articles/2005/MZ2005007.aspx
The exception is thrown because your icon cannot be located. You will probably need to compiles your resources under one .dll and put this under en-US subfolder on your project output. It did the trick for me at least. There are probably other solutions to your problem too.
Do not panic like I did. The root cause of the problem is that the compiled resource file is different from the one that is asked to load at runtime. This happens because the underlying build-script cannot detect the filename or namespace changes made after the form is created.
For example, At first we started a project named x . And our $(RootNamespace) becomes x. And we created a form named y. So our XML resource file y.resx gets compiled into x.y.resource . At this point the icon change works.
Now somehow we changed the project name or the namespace to z. But our $(RootNamespace) remains the x. While at compile-time it wrongly generates old x.y.resource, but at links-time it links z.y.resource. And at this point the icon change does not work.
It can also happen if the form is under some nested namespace which is not known in the project file.
It can be fixed by changing the compilation output of the y.resx file . It can be done by right-clicking the resource and changing the Resource Logical Name to $(RootNamespace).%(Filename).resources .
I will also make sure that ProjectName,AssemblyName and RootNamespace are the same in the .vcxproj file. Somehow if the form is declared under a nested namespace like RootNamespace.gui , then the output file of the resource should be $(RootNamespace).gui.%(Filename).resources .

Anyway to get Visual Studio C++ to autocomplete parameter list?

Very specific issue with a specific piece of software, but I hope you fine folks can help!
I define a class in a header.h file that has a few method declarations that take parameters
class Lazy{
void complainForever(char * complaint, float forever = INFINITY);
};
Then I go into the Lazy.cpp file to define that function. Here is a psuedo timelapse of just how lazy I am.
void Lazy:: // <-- autocomplete kicks in, select method and hit enter
void Lazy::complainForever // <-- parameter list missing, completely defeating purpose
At that point, I either have to type it by hand, or copy/paste the parameter list from the header.h file
The question is this! Is there a keyboard shortcut or any method at all for having autocomplete take care of the parameter list for me?
Thank you in advance!
Why don't you try Visual Assist X. It isn't free though.
Once you are done defining the class in your header file, try to update Intellisense.
Updating intellisense can be achieved by reloading your project/solution. Once your intellisense is update, when you try to implement the class definition - you get the autocomplete feature on your newly defined class enabled. This includes the individual function prototypes as defined in the header.
Keyboard shortcut to display intellisense is Ctrl + Space.
Thanks