bonob
bonob

Reputation: 181

Header not refreshed - Visual C++ 2012

Using Visual C++ 2012, without precompiled headers:

When I change a header file that is included in multiple files, the change is not taken into account when building. If I rebuild all, the change is taken into account.

Reproduction case:

include.h

#ifndef INCLUDE_H_
#define INCLUDE_H_

class A {
public:
   A(int i) : i_(i) { }
   int i_;
};

class B {
public:
  B(int i = 1) : a_(i) { }
  A a_;
};

#endif INCLUDE_H_

dummy.cpp

#include "include.h"

main.cpp

#include <iostream>
#include "include.h"

int main(int, char**) {
  B b;
  std::cout << b.a_.i_ << std::endl;
  return 0;
}

This outputs 1.

Now I change int i = 1 to int i = 2 in include.h; I build and run, it outputs 1! I rebuild and run, it outputs 2.

Am I missing something or is this really a bug in Visual Studio? If the latter, is there a known workaround? (Other than re-building at every step)

Upvotes: 6

Views: 1440

Answers (2)

I've been through such thing in the past.

Do you use precompiled headers? If you do please remove any project specific headers from the PCH. That is a lame mistake. Only place external, nonchanging headersin PCH, like C/C++ standard headers, Windows headers, Boost etc.

Upvotes: 0

Mark Ransom
Mark Ransom

Reputation: 308206

The header file must be part of the project. If it isn't the project will still build i.e. the compiler can find it, but Visual Studio won't track the date of the file.

Upvotes: 3

Related Questions