开发者

Calling cli::array<int>::Reverse via a typedef in C++/CLI

开发者 https://www.devze.com 2023-01-02 12:51 出处:网络
Here is what I\'m trying: typedef cli::array<int> intarray; int main(){ intarray ^ints = gcnew intarray { 0, 1, 2, 3 };

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 wh开发者_Go百科en 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?


That is an interesting question. Both the following notations do work

   ints->Reverse(ints);
   array<int>::Reverse(ints);

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消