C++ cli C+中存在多个索引属性的问题+/CLI
我正在尝试在C++/CLI中实现列表>的索引属性。我正在使用Visual Studio Express 2013。无论我做什么,这个简单的class语句都不会编译。索引属性的get函数的错误消息是default::get:function不接受2个参数,然后default::get:function不接受0个参数。set函数的错误消息非常类似-default::set:函数不接受3个参数,然后default::set:函数不接受0个参数 我对编码类和属性非常陌生;这可能是我忽略的一些简单的事情。我被难住了 守则如下:C++ cli C+中存在多个索引属性的问题+/CLI,c++-cli,C++ Cli,我正在尝试在C++/CLI中实现列表>的索引属性。我正在使用Visual Studio Express 2013。无论我做什么,这个简单的class语句都不会编译。索引属性的get函数的错误消息是default::get:function不接受2个参数,然后default::get:function不接受0个参数。set函数的错误消息非常类似-default::set:函数不接受3个参数,然后default::set:函数不接受0个参数 我对编码类和属性非常陌生;这可能是我忽略的一些简单的事情。
#pragma once;
#include "stdafx.h"
using namespace System;
using namespace System::Collections::Generic;
public ref class Multilist
{
private:
List<List<int>^>^ mlist;
public:
Multilist()
{
mlist = gcnew List<List<int>^>;
}
property int default[int,int]
{
int get( int indx1, int indx2 )
{
if( indx1<0||indx2<0 )
throw ("Cannot have negative index values");
else
return mlist[indx1, indx2];
}
void set( int indx1, int indx2, int value )
{
mlist[indx1,indx2] = value;
}
}
};
#pragma一次;
#包括“stdafx.h”
使用名称空间系统;
使用命名空间System::Collections::Generic;
公共引用类多重列表
{
私人:
列表^mlist;
公众:
多重列表()
{
mlist=新列表;
}
属性int默认值[int,int]
{
int-get(int-indx1,int-indx2)
{
if(indx1默认属性在最近的编译器版本中被破坏
使用非保留名称,并使用属性指定C#要使用的默认值。正确的语法是mlist[indx1][indx2]
。