Can anybody tell me what is wrong ....

A

Allen Maki

/*

I am trying to practice multidimensional array in a managed class using
dynamical allocation.

If I tried to compile the following codes, I would get the under mentioned

c2440 error message. It is only practice. You may notice that I am not using
"private"

or constructor here. Can anybody tell me what is wrong and how I can rewrite
that line right?

Thanks a lot.

*/

#include "stdafx.h"

#include <string.h>

#include <string>

#using <mscorlib.dll>

#include <tchar.h>

using namespace System;

using namespace std;

__gc class Month

{

public:

//private:

static const int weekOfMonth = 2;

static const int dayOfWeek = 3;

int pDaysOfMonth[,];

};


int _tmain()

{

Month *March;

March = new Month;

March->pDaysOfMonth = new int[6,7]; //<-----error C2440: '=' : cannot
convert

//from 'int *' to 'int __gc[,]'Can only

//convert a __gc array to or from Object * or Array *

March->pDaysOfMonth[0,0] = 3;

March->pDaysOfMonth[1,1] = 4;

return 0;

}

//Allen
 
C

Carl Daniel [VC++ MVP]

Allen said:
/*

I am trying to practice multidimensional array in a managed class
using dynamical allocation.

If I tried to compile the following codes, I would get the under
mentioned
c2440 error message. It is only practice. You may notice that I am
not using "private"

or constructor here. Can anybody tell me what is wrong and how I can
rewrite that line right?

Thanks a lot.
March->pDaysOfMonth = new int[6,7];

March->pDaysOfMonth = __gc new System::Int32[6,7];

-cd
 

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