0
votes

I am having problems creating a managed class with namespace in visual studio 2012 Windows Runtime Component of C++.

Below is the code:-

#pragma once
#include <string>
using namespace std;

namespace WindowsRuntimeComponent1
{
     public ref class Class1 sealed
     {
           public:
               Class1();
               string getString(string desc);
      };
}

i'm getting error at 'public' which it expected a declaration. beside that, exception return by visual studio 2012 is error C2059:syntax error:'public', error C2143:syntax error:missing ';' before '{', error C2447:'{':missing function header (old-style-formal list?)

Can anyone help me solve this problem. Thank you.

1
It is not a runtime error. You'll get this kind of compile error when the compiler isn't configured properly, not compiling with the /ZW option to enable the C++/CX language extension. Be sure to get started with the correct project template. Project + Properties, General, "Windows Store App Support" needs to be Yes. - Hans Passant

1 Answers

1
votes

oYou have to change the runtime compiler. Go to Project -> Properties -> General and change it to "Common Language Runtime Support to /clr".

EDIT: Well, there is no need to worry about all the compiler errors. Google is your friend! if you don't know how to fix it, just look for it. All errors are described in detail. But most of the errors are self-explanatory, e.g. "error C4703, potentially uninitialized local pointer variable used" says you have to initialize your var int *xxx=0;.