Visual studio 2015 inherit #include

Mar 9, 2020 at 10:12am
1
2
//incl.h
#include <stdint.h> 

1
2
3
4
5
6
7
//test.h
#ifndef TEST__
#define TEST__

int32_t value;

#endif 


1
2
3
4
5
6
7
8
//main.cpp
#include "test.h"
#include "incl.h"
#include <iostream>

int main() {
  std::cout << "Hello World!\n";
}


I build it on repl.it , It is OK,
But when I build on Visual studio 2015.
=> identifier "int32_t" is undefined
How to solve it?
Thanks.
Mar 9, 2020 at 11:26am
Hello kakaducsy,

Try one of these.

1
2
3
4
5
6
7
8
9
//main.cpp
#include <iostream>
#include "incl.h"// <--- Sometimes order does make a difference.
#include "test.h"

int main()
{
  std::cout << "Hello World!\n";
}


You are including "test,h" before you include the header file "stdint.h", so when you get to "test.h" the "int32_t" is not defined yet.

Or even this. Better than putting an #include <???> in a header file.
1
2
3
4
5
6
7
8
9
10
//main.cpp
#include <iostream>
#include <stdint.h>
//#include "incl.h"
#include "test.h"

int main()
{
  std::cout << "Hello World!\n";
}
Mar 9, 2020 at 12:30pm
test.h depends on int32_t, so you should be #including <cstdint> (stdint.h in C) within test.h
Last edited on Mar 9, 2020 at 12:31pm
Mar 10, 2020 at 2:28am
Hi Handy Andy and Ganado ,

1
2
3
4
5
6
7
8
9
//main.cpp
#include <iostream>
#include "incl.h"// <--- Sometimes order does make a difference.
#include "test.h"

int main()
{
  std::cout << "Hello World!\n";
}

This code can run on https://repl.it
But cannot run on VS2015, What do I need any config for VS2015?
It seem try build "*.h" file
Mar 10, 2020 at 11:38am
What is the error?
Mar 10, 2020 at 6:10pm
Hello kakaducsy,

I worked up the program with the two ".h" files on VS2017. This compiled with out any errors and ran.

Not sure why you are having problems unless you changed something after VS 2015 was installed.

Along with what Ganado said what error messages are you getting. Copy and post what the IDE puts out.

Andy
Topic archived. No new replies allowed.