Hello. All i am having trouble with using public ref classes and gcnew. The following code will show you my situation.

Vector2 class

/// </summary>
public ref class vector2{

public:
    vector2(void):x(""),y(""){};
System::String ^x;
System::String ^y;
void Position(System::String ^ X, System::String^ Y){

x=X;
y=Y;


};


};

Add picture class

public ref class AddPicture {

public:

    AddPicture(void):fileName(""){}
    vector2 ^ V1,^ V2;


    System::String ^ fileName;
    void newAddPicture(vector2 ^ v1,vector2 ^ v2,System::String ^ filename){


    fileName = filename;

    V1=v1;
    V2=v2;

    }

then this is where construct these

    this->newAp = gcnew AddPicture();



    vector2 ^vv1,^vv2;
    vv1= gcnew vector2();
    vv2= gcnew vector2();
    vv1->Position(posx,posy);
    vv2->Position(sizex,sizey);



    newAp->newAddPicture(vv1,vv2,MyString1);

if i want to access newAp->V1->x; or y an error shows up that says null reference exception unhandled. I cant figure it out, i dont know how to use ref class's can anyone tell me how to access these kinda of classes like im trying to above.thanks

Recommended Answers

All 5 Replies

This is C++? Not on any planet I am familiar with, and I have only been programming C++ for 20 years, professionally!

One question though, bogus syntax notwithstanding - what is gcnew? Is that a garbage-collecting operator new allocator? From what I know, this is a .NET term, which has zip, zero, zilch to do with C++. So, if this question is for a C# program, then post it to that discussion thread!

This is C++? Not on any planet I am familiar with, and I have only been programming C++ for 20 years, professionally!

C++/CLI, it's C++ extended to meet CLI requirements and fit into the .NET framework as a managed language.

C++/CLI, it's C++ extended to meet CLI requirements and fit into the .NET framework as a managed language.

It still is NOT C++! It is C++ "extended" to work with C# and other .NET languages. Also, the rest of his code may be valid with .NET, but NO C++ compiler I work with, except possibly Visual Studio .NET (which I avoid like the plague), will compile this code. So, it does not, IMO, belong in this C++ discussion thread.

So, it does not, IMO, belong in this C++ discussion thread.

Your opinion doesn't define what's topical for this forum. If you don't know C++/CLI or don't agree with it, you're not required to participate in any threads about it.

@jonnyboy12: Where is newAp defined in the class?

@rubberman: Things change. Have you seen MFC? I coded in that for YEARS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.