A curiosity about the VS2010 text editor

Given the A.h file below (note that on purpose, I didn't include the <iostream> header in this file). The VS2010 text editor then shows a red line below std, as it doesn't recognize this name.

class A
{
    public;
    A() throw(std::bad_alloc);
};

But if I include the <iostream> header in the A.cpp file as below, the red line disappears in the A.h file, even when the A.cpp is closed. How is this possible ?

#include <iostream>
#include "A.h"
A::A() { throw std::bad_alloc(); }

Answers


Add a new C++ file that does include A.h but doesn't include <iostream>. The red underline under std will reappear.

VS2010 knows which files include that header file. If any of them do not know about std, it will point out the issue.

But you're right, if you switch the order of the includes so that the project won't compile, it still removes the red underline.


Visual Studio is written for all C++ programmers. This means that it cannot assume that header files always include everything needed by them. To put red lines under everything that isn't explicitly included by a header would mean a lot of false positives for those developers who work in a strict environment where headers are included in a specific order, with dependencies.

So Visual Studio tries to figure out what you mean, rather than assuming that your headers are able to stand on their own.

It may not be the best practice in your source, but they have to account for it.


Need Your Help

Insert serialVersionUID with ANT

serialization ant build suid

Is it possible to use an ANT task to insert the serialVersionUID property into all classes that implement Serializable?

retrive data from other query in php

php javascript mysql

well I'm working on a project , I'm using mysql &amp; php to retrive my data from my table

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.