Zebrafish
Zebrafish

Reputation: 14114

Visual Studio Intellisense not recognising class member in bracket initialisation

At first I thought this might be a language limitation of C++, but this actually compiles, it's just that Intellisense doesn't recognise the class members for some reason:

struct MyStruct
{
    int member;
};

MyStruct staticObj;

int main()
{
    MyStruct localObj;
    int arr1[] = { 1, 2, localObj.member };      // When typing localObj Intellisense says it has no members
    int arr2[] = { 1, 2, staticObj.member };     // When typing staticObj Intellisense says it has no members

}

I thought that the fact that C++ doesn't support variable length arrays might be the explanation, but this is a compile-time-known array length, just that its value isn't known. Is this a bug I'm having? Also it compiles fine on Ideone.com

Upvotes: 0

Views: 559

Answers (2)

eerorika
eerorika

Reputation: 238401

At first I thought this might be a language limitation of C++, but this actually compiles

This program is well formed.

I thought that the fact that C++ doesn't support variable length arrays might be the explanation, but this is a compile-time-known array length, just that its value isn't known.

Indeed, there is no VLA in the code and VLA has nothing to do with this.

Is this a bug I'm having?

MyStruct does have a member, so if intellisense says otherwise, it seems to be a bug.

Upvotes: 2

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385264

This is obviously an Intellisense bug.

Intellisense should not be relied upon for verifying the correctness of your code.

Sometimes, unfortunately, that means you have to put up with false-positive red squiggly lines.

Upvotes: 3

Related Questions