Managed C++ Classes

  • Thread starter Thread starter peter.mcclymont
  • Start date Start date
P

peter.mcclymont

I am used to C++, but not managed C++.

All I want to do is write a class to reverse a string. Don't ask me
why, it is not for a real world application. Actually it is for a test.

My code looks like this at the moment. It is not finished yet of
course, but I am having trouble compiling, it says this,

..\Reverse.cpp(8) : error C4980: '__gc' : use of this keyword requires
/clr:oldSyntax command line option

Am I on the right track?

#include "stdafx.h"
#include <vcclr.h>

using namespace System;

public __gc class ReverseString
{
public:
ReverseString() {};
~ReverseString() {};

private:
String ^szString;
};

int main(array<System::String ^> ^args)
{
ReverseString reverseString();

Console::WriteLine(L"Hello World");
return 0;
}
 
I have got a bit further on this,

I now have this,

#include "stdafx.h"
#include <vcclr.h>

using namespace System;

public ref class ReverseString
{
public:
ReverseString(String ^szString)
{
this->szString = szString;
};
~ReverseString() {};

public String^ ReverseString::ReturnReverseString()
{
return "tset";
};

private:
String ^szString;
};

int main(array<System::String ^> ^args)
{
ReverseString reverseString("Test");

Console::WriteLine(reverseString.ReturnReverseString());
Console::WriteLine(L"Hello World");
return 0;
}


Still not really sure what I am doing, cannot get the
ReturnReverseString function to compile.

It now says this,

..\Reverse.cpp(17) : error C2144: syntax error : 'System::String' should
be preceded by ':'
 
Back
Top