Std :: string.npos validity

Has it std::string.nposever been valid? (Unlike the right one std::string::npos.)

I see this a lot in the old project I'm working on, and it does not compile with VS2010.

Is this some of the pre-standard days?

+5
source share
3 answers

No, it std::string.nposhas never been valid, and no, this is not something from the pre-standard days.

I see other answers that mention that MSVC allowed this notation.

MSVC . , -t21. Windows GUI - , main. , Microsoft Herb Sutter ( , ), . , , , .

+3

-, C , :: . :

class X {
public:
    void f();
};

void X.f() // a dot! see D&E 2.3
{ 
}

std . , std::string.npos Microsoft ( ?). , .

+5

, , MSVC.

#include <iostream>
struct A
{
    static int a; 
};
int A::a;
int main()
{
    std::cout << A.a;
}

MSVC9.0

1 C4832: '.' UDT 'A'

++ className.memberName ( object.staticMemberName).

My common sense tells me that if MSVC realizes that this is not standard and gives a warning, we can disable this extension. Go to Project Propertied -> C/C++ -> Languageand set Disable Language Extensionsto Yes. Do you think something has changed? Of course not, the compiler still accepts illegal code with the same warning. I sometimes wonder what it actually does Disable Language Extensions...

+3
source

All Articles