通过 C++/CLI 中的 typedef 调用 cli::array::Reverse
这是我正在尝试的:
typedef cli::array<int> intarray;
int main(){
intarray ^ints = gcnew intarray { 0, 1, 2, 3 };
intarray::Reverse(ints); // C2825, C2039, C3149
return 0;
}
编译导致以下错误:
.\ints.cpp(46) : error C2825: 'intarray': must be a class or namespace when followed by '::'
.\ints.cpp(46) : error C2039: 'Reverse' : is not a member of '`global namespace''
.\ints.cpp(46) : error C3149: 'cli::array<Type>' : cannot use this type here without a top-level '^'
with
[
Type=int
]
我在这里做错了什么吗?
编辑:这是编译器错误吗?
Here is what I'm trying:
typedef cli::array<int> intarray;
int main(){
intarray ^ints = gcnew intarray { 0, 1, 2, 3 };
intarray::Reverse(ints); // C2825, C2039, C3149
return 0;
}
Compilation resulted in the following errors:
.\ints.cpp(46) : error C2825: 'intarray': must be a class or namespace when followed by '::'
.\ints.cpp(46) : error C2039: 'Reverse' : is not a member of '`global namespace''
.\ints.cpp(46) : error C3149: 'cli::array<Type>' : cannot use this type here without a top-level '^'
with
[
Type=int
]
Am I doing something wrong here?
Edit: Is this a compiler bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个有趣的问题。以下两种符号都可以
按您的预期工作。由于 typedef 引入了同义词,我希望它对您有用,但显然在 VC++ 2008 Express 中不行。
That is an interesting question. Both the following notations do work
as you'd expect. Since typedef introduces a synonym, I'd expect it to work for you, but it obviously doesn't in VC++ 2008 Express.
你应该使用 .调用成员函数。 :: 仅用于编译时解析。
编辑:
哎呀,我完全误读了你的代码。您应该使用 ints.Reverse(),而不是 IntArray::Reverse(ints)。此外,C++/CLI 中 .NET 类型的规则完全有可能与 C# 中 .NET 类型的规则相同 - 也就是说,应该始终使用该点。
You're supposed to use . to call member functions. :: is only used for compile-time resolutions.
Edit:
Whoops, I totally misread your code. You should use ints.Reverse(), rather than IntArray::Reverse(ints). Furthermore, it's totally possible that the rules for .NET types in C++/CLI are the same for .NET types in C#- that is, that dot should always be used.