Skip to main content
GameDev.net gamedev.net
🔒 Locked

Managed C++

Started by ApolloCay Jun 25, 2005 at 12:58 AM 1 replies 4.5k views
Original Post
ApolloCay
ApolloCay
I am trying to convert a c# program over to managed c++. Problem is I'm having some difficulty converting it over. I'm still relatively new to .NET so this is a good learning experience for me. One of the functions in a class called Attributelist looks like this:

public Attributelist():base("","")
{
  m_list = new ArrayList();
}






the Attributelist is a class that inheities from another class called Attribute. How do I convert this function over. As you can see, it uses the 'base' keyword from C#.. Is there an equivelent keyword in MC++ that I need to use? Another line of code giving me problems is this:

// C# version
public void Set(string name,string value)
{
...
Attribute a = this[name];
...
}

// MC++ version
public void Set(String* name, String* value)
{
...
Attribute* a = this[name];
...
}






I get this: error C2107: illegal index, indirection not allowed Here is another:

// C# version
for ( int i=0;i<m_list.Count;i++ ) 
    rtn.Add( (Attribute)this.Clone() );

// MC++ version
for (int i=0; i<m_list->Count; i++) 
    rtn->Add(static_cast<AttributeHTML*>(this->Clone()));






Here are the errors I get: error C2845: '[' : cannot perform pointer arithmetic on __gc pointer 'HTML::AttributeList __gc *const ' error C2227: left of '->Clone' must point to class/struct/union Here is one last one:

// C# version
public Attribute this[int index]
{
...
}






This one I don't know what to do with. It is part of the AttributeList class were attribute is one entity of the list. Thanks for any help anyone can provide.
Amnesty
Amnesty
Don't try to convert on a line by line basis. Just convert the functionality.
The way you are using this in C++ is illegal, hence the errors.
"I turned into a driveway I thought was mine and crashed into a tree I don't have."- a real insurance claim
MaulingMonkey
MaulingMonkey
Quote:
Original post by ApolloCay
I am trying to convert a c# program over to managed c++.

Problem is I'm having some difficulty converting it over. I'm still relatively new to .NET so this is a good learning experience for me.

One of the functions in a class called Attributelist looks like this:
*** Source Snippet Removed ***

the Attributelist is a class that inheities from another class called Attribute. How do I convert this function over. As you can see, it uses the 'base' keyword from C#.. Is there an equivelent keyword in MC++ that I need to use?


I havn't used C#, but assuming that base("","") means "call Attribute's constructor with the arguments "" and "" ", then the syntax for that would be like so in C++:
public: Attributelist() : Attribute("",""){}

Quote:
Another line of code giving me problems is this:
*** Source Snippet Removed ***
I get this: error C2107: illegal index, indirection not allowed


That's because "this" is a pointer. Chances are you want:
Attribute* a = (*this)[name];

This is a bit of a stab in the dark however, but this will call Attributelist::operator[] (or Attribute::operator[] if there is none) with that string argument.

Quote:
Here is another:
*** Source Snippet Removed ***
Here are the errors I get:

error C2845: '[' : cannot perform pointer arithmetic on __gc pointer 'HTML::AttributeList __gc *const '
error C2227: left of '->Clone' must point to class/struct/union


Again, looks like you want to replace "this" with "(*this)". Calling operator[] on a pointer in C++ does pointer math and a dereference, which I'm guessing isn't what you want :).

Quote:
Here is one last one:
*** Source Snippet Removed ***
This one I don't know what to do with. It is part of the AttributeList class were attribute is one entity of the list.

Thanks for any help anyone can provide.


Again, more wild guesses, but I have the feeling this is what you want:

public: Attribute operator[] ( int index ){...}


This function will be called when you do:

Attributelist mylist;
Attribute myattribute = mylist[ 4 ];

Or similarly:

Attributelist * mylist = new Attributelist;
Attribute myattribute = (*mylist)[ 4 ];

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.