代码之家  ›  专栏  ›  技术社区  ›  Agnel Kurian

调用CLI::Reals<int >::通过C++中的Type实现反向

  •  0
  • Agnel Kurian  · 技术社区  · 16 年前

    我正在尝试的是:

    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
            ]
    

    我是不是做错了什么?

    2 回复  |  直到 15 年前
        1
  •  1
  •   Reilly    16 年前

    这个问题很有趣。以下两种符号都有效

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

    如你所料。因为typedef引入了一个同义词,所以我希望它对您有用,但在VC++2008 Express中显然不行。

        2
  •  -1
  •   Puppy    16 年前

    你应该用。调用成员函数。*仅用于编译时解析。

    编辑: 哎呀,我完全看错了你的代码。你应该用国际反向(),而不是IntArray::Reverse(ints)。此外,C++中的.NET类型的规则完全可能与C语言中的.NET类型相同。