0

我正在尝试使用 __declspec 属性并在使用多个索引时遇到一些奇怪的错误。我在 Visual Studio 中收到错误消息:“表达式必须是指向完整对象类型的指针”,但代码似乎运行良好。这是我正在使用的代码:

#include "stdafx.h"

template<typename T>
class testClass
{
public:
    __declspec (property (get = GetValue, put = PutValue))
        T test[][];

    T GetValue(int x, int y)
    {
        return _internalVal[x][y];
    }

    void PutValue(int x, int y, T lValue)
    {
        _internalVal[x][y] = lValue;
    }
private:
    T _internalVal[3][3];

};


int _tmain(int argc, _TCHAR* argv[])
{

    testClass<int> tc;
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){

            tc.test[i][j] = i * j;
        }
    }
    return 0;
}

此示例在使用多维属性的模板类上使用 __declspec 属性。如果我删除一组括号和参数,似乎错误消失并且代码按预期运行。就像现在的代码一样,它会在 Visual Studio 中引发错误并仍在运行。

为什么这是一个问题?我在一个团队中工作,如果出现错误,其他人会不高兴,并且可能会认为代码不起作用,尽管它会。有没有办法抑制此类错误?为什么会这样?

4

0 回答 0