R
raylopez99
Hi all,
I'm getting a runtime error for the below program, though it compiles
fine. The culprit seems to be the managed array--it doesn't exist.
What am I doing wrong?
RL
// OverL2_simple.cpp : main project file.
#include "stdafx.h"
#include "AClass.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
AClass ^A10 = gcnew AClass(); //see AClass.h, .cpp below for
declaration/definition
for (int j=0; j<(A10->a1->Length); j++){
Console::WriteLine("a1 is: {0}", A10->a1[j]);
}
// Unhandled Exception: System.NullReferenceException: Object
reference not set to an instance of an object.
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
// Aclass.h
#pragma once
using namespace System;
ref class AClass
{
public:
AClass(void);
int pubint;
array<int>^ a1; //this array is causing problems
private:
int privint;
};
//////////////////////////////////////////////
// Aclass.cpp
#include "StdAfx.h"
#include "AClass.h"
//
AClass::AClass(void): pubint(1),privint(1)
{
array<int>^ a1 = {1,2,3,4,5}; //compiles but give runtime error
}
/*
//compiles but give runtime error:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
*/
I'm getting a runtime error for the below program, though it compiles
fine. The culprit seems to be the managed array--it doesn't exist.
What am I doing wrong?
RL
// OverL2_simple.cpp : main project file.
#include "stdafx.h"
#include "AClass.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
AClass ^A10 = gcnew AClass(); //see AClass.h, .cpp below for
declaration/definition
for (int j=0; j<(A10->a1->Length); j++){
Console::WriteLine("a1 is: {0}", A10->a1[j]);
}
// Unhandled Exception: System.NullReferenceException: Object
reference not set to an instance of an object.
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
// Aclass.h
#pragma once
using namespace System;
ref class AClass
{
public:
AClass(void);
int pubint;
array<int>^ a1; //this array is causing problems
private:
int privint;
};
//////////////////////////////////////////////
// Aclass.cpp
#include "StdAfx.h"
#include "AClass.h"
//
AClass::AClass(void): pubint(1),privint(1)
{
array<int>^ a1 = {1,2,3,4,5}; //compiles but give runtime error
}
/*
//compiles but give runtime error:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
*/