creating arrays of class pointers within a class.

.net , cpp.net France
  • 14 years ago

    I'm writing a program in which I need to, within a class, create an array that contains pointers to, or instances of, another class. I also want to be able to use the .net array class, because I want to use a for loop with the upper bound being the length of an input array of the class. I've tried a bunch of ways of doing this, but I've run out of ideas. Right now my code is like this:

    public class Class1{}

    public

    class Class2

    {

    public

    :

             array<Class1*, 1>^Class1Array;

             Class1Array->Length;

    }

    or thats the gist of it. I get this error when I try to build it:

    error C3265: cannot declare a managed 'Class1Array' in an unmanaged 'Class2'

    may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap

    I looked up the error code in the MSDN database and it said to declare the class as a ref class, which I tried, and I got these errors:

    error C2143: syntax error : missing ';' before '->'

    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    error C2238: unexpected token(s) preceding ';'

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”