C++ CLI 嵌套默认索引
C++ CLI nested default index
我有一个包含对象列表的 class,其中有一个默认索引 属性。每个对象都有一个列表,我想为其创建另一个默认索引。
public ref class Foo
{
//List of Bars
public:
property Bar^ default[int]; //Returns a Bar
}
public ref class Bar
{
//List of things
public:
property Thing^ default[int]; //Returns a Thing
}
而不是用...调用它
Foo.Bars[i].Things[k]
...我想做类似...
Foo[i][k]
...去拿我的东西。
它告诉我...
The function Foo::default[int]::get cannot be called with the given argument list
Argument types are get(int, int).
...好像我正在尝试调用 get(int, int) 但这不是我的意图。
如果我在 Foo 中有另一个默认索引,它是二维的,其中第二个维度 returns 来自酒吧的东西,但我希望有一个实现,其中 Thing无法从 Foo 访问。
非常感谢您的指导。
这个:
public ref class Thing
{
};
public ref class Bar
{
//List of things
public:
property Thing^ default[int]
{
Thing^ get(int index)
{
return gcnew Thing();
}
}//Returns a Thing
};
public ref class Foo
{
//List of
public:
property Bar^ default[int]
{
Bar^ get(int index)
{
return gcnew Bar();
}
}
};
然后
Foo^ test = gcnew Foo();
Thing^ res = test[5][3];
编译正确。您可能没有包含 get
部分,或者您将 Foo
class 放在 Bar
class.
之前
我有一个包含对象列表的 class,其中有一个默认索引 属性。每个对象都有一个列表,我想为其创建另一个默认索引。
public ref class Foo
{
//List of Bars
public:
property Bar^ default[int]; //Returns a Bar
}
public ref class Bar
{
//List of things
public:
property Thing^ default[int]; //Returns a Thing
}
而不是用...调用它
Foo.Bars[i].Things[k]
...我想做类似...
Foo[i][k]
...去拿我的东西。
它告诉我...
The function Foo::default[int]::get cannot be called with the given argument list
Argument types are get(int, int).
...好像我正在尝试调用 get(int, int) 但这不是我的意图。
如果我在 Foo 中有另一个默认索引,它是二维的,其中第二个维度 returns 来自酒吧的东西,但我希望有一个实现,其中 Thing无法从 Foo 访问。
非常感谢您的指导。
这个:
public ref class Thing
{
};
public ref class Bar
{
//List of things
public:
property Thing^ default[int]
{
Thing^ get(int index)
{
return gcnew Thing();
}
}//Returns a Thing
};
public ref class Foo
{
//List of
public:
property Bar^ default[int]
{
Bar^ get(int index)
{
return gcnew Bar();
}
}
};
然后
Foo^ test = gcnew Foo();
Thing^ res = test[5][3];
编译正确。您可能没有包含 get
部分,或者您将 Foo
class 放在 Bar
class.