0

I am trying to implement an indexed property for a List> in C++/CLI. I'm using Visual Studio Express 2013. No matter what I do the simple class statement won't compile. The error message for the get function of the indexed property is default::get:function does not take 2 arguments, and then default::get:function does not take 0 arguments. The error message for the set function is very similar - default::set:function does not take 3 arguments, and then default::set:function does not take 0 arguments.

I'm very new to coding classes and properties; it could be something simple that I'm overlooking. I'm stumped.

The code follows:

#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;
        }
    }
};
4

1 回答 1

0

默认属性在最近的编译器版本中被破坏。

使用非保留名称,并使用属性指定 C# 使用的默认值。

于 2013-11-11T14:52:22.567 回答