We created a Reverse Phonebook Lookup in our class. Our school system uses VS 2013 on our machines and I use VS 2017 on my home PC. The program built at school runs fine on VS 2013 but when I loaded it with VS 2017 and tried to execute it, I got the following three errors:
Severity Code Description Project File Line Suppression State Error (active) E0442 too few arguments for class template "std::array" GUIPhoneBook c:\Users\diabl\source\repos\GUIPhoneBook\GUIPhoneBook\MyForm.cpp 12
Severity Code Description Project File Line Suppression State Error C2976 'std::array': too few template arguments GUIPhoneBook c:\users\diabl\source\repos\guiphonebook\guiphonebook\myform.cpp 13
Severity Code Description Project File Line Suppression State Error C3699 '^': cannot use this indirection on type 'std::array' GUIPhoneBook c:\users\diabl\source\repos\guiphonebook\guiphonebook\myform.cpp 13
This is what I have in MyForm.cpp
#include "MyForm.h"
#pragma once
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int Main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew GUIPhoneBook::MyForm());
return 0;
}
I am fairly new to c++ and building the GUI so I have no idea what this means. I searched this forum and read the solutions to problems that were kind of similar to this but they didn't work. Does anybody have any ideas on a fix? Thanks.
I am fairly new to c++...
Standard 'learning the language' warning: This isn't C++ you're writing, it's C++/CLI. C++/CLI is a language from Microsoft intended to allow C# or other .Net languages to interface with standard C++. In that scenario, C++/CLI can provide the translation between the two. If you're still learning C++, please do not start with C++/CLI. In order to effectively write in C++/CLI, one should already know both C++ and C#, and then there's still things to learn about C++/CLI. If you want to learn C++, stick with standard (unmanaged) C++. (In Visual Studio, create a "Win32" C++ project.) If you want to learn managed code, then I would use C#.
That said...
int Main(array<System::String ^> ^args)
I haven't investigated why, but for some reason VS2017 is finding std::array
first, while VS2013 is finding cli::array
first. As you can probably guess from the error message you're getting, those two classes take different template/generic parameters. (std::array
takes a type and a size, cli::array
takes a type and the size gets specified when the object is created.)
To fix this, you can explicitly specify the cli::
in the declaration of main. There also might be a using namespace std;
that needs to be removed, or adding using namespace cli;
might work as well.