Hi, I have been attempting to learn visual c++ recently. The book that I'm reading showed an example with enums in C++/CLI.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "stdafx.h"
usingnamespace System;
enumclass Suit{ Clubs, Diamonds, Hearts, Spades };
int main(array<System::String ^> ^args)
{
Suit suit = Suit::Clubs;
int value = safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the value is {1} ", suit, value);
return 0;
}
The expected result was suppose to be: Suit is Clubs and the value is 0.
However, I was not able to compile the above code successfully. Apparantly the book says that by outputting the value of suit, the value would be displayed as Clubs instead of 0. However I am not able to do so as the code gives me errors. Anyone knows why? Thanks in advance for any help that I can get! :)
Error that i received:
1 2 3 4 5 6 7
1
1> ConsoleApplication1.cpp
1>ConsoleApplication1.cpp(28): error C2665: 'System::Console::WriteLine' : none of the 19 overloads could convert all the argument types
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.5\mscorlib.dll: could be 'void System::Console::WriteLine(System::String ^,...cli::array<System::Object ^,1> ^)'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.5\mscorlib.dll: or 'void System::Console::WriteLine(System::String ^,System::Object ^,System::Object ^)'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.5\mscorlib.dll: or 'void System::Console::WriteLine(cli::array<wchar_t,1> ^,int,int)'
1> while trying to match the argument list '(const wchar_t [34], Suit, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========