C++ Visual Studio 2013 Strange error but code runs

120 views Asked by At

I am trying to use __declspec properties and getting some strange errors when using multiple indicies. I get the error: "expression must be a pointer to a complete object type" in visual studio, but the code seems to run fine. Here is the code I am using:

#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;
}

This example is using a __declspec property on a template class using a multidimensional property. If i remove one set of brackets and parameters, it seems the error goes away and the code runs as expected. As the code is now, it throws an error in visual studio and still runs.

Why is this a concern? I work in a team and the others will not be pleased if errors appear, and likely will assume the code wont work, although it will. Is there a way to suppress such errors? Why is this happening?

0

There are 0 answers