Managed C++ Classes

  • Thread starter peter.mcclymont
  • 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:blush:ldSyntax 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;
}
 
P

peter.mcclymont

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 ':'
 
H

Holger Grund

public String^ ReverseString::ReturnReverseString()
As the error message suggest this should be
public: /* note, the colon */
.\Reverse.cpp(17) : error C2144: syntax error : 'System::String' should
be preceded by ':'
-hg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top