header-files

What is the scope of a pragma directive?

◇◆丶佛笑我妖孽 提交于 2019-12-23 06:48:35
问题 What is the scope of a pragma directive? For example, if I say #pragma warning(disable: 4996) in a header file A that is included from a different file B, will that also disable all those warnings inside B? Or should I enable the warning at the end of file A again? 回答1: It is till the end of the translation unit. Informally, a TU is the source file with its include files. The usual pattern is this: #pragma warning (push) //save #pragma warning (disable: xxxx) #pragma warning (disable: yyyy) .

Cyclic Dependency in reentrant flex / bison headers with union YYSTYPE

戏子无情 提交于 2019-12-23 02:34:38
问题 I have a problem where I believe there is a cyclic dependency between the headers generated by flex and bison . The type yyscan_t is defined in the lex header and needed in the yacc header. The macro YYSTYPE is defined in the yacc header and needed in the lex header. No matter which order I import the two headers, the other will not be happy. reentrant.lex: %{ #include "reentrant.yacc.h" %} %option reentrant bison-bridge %% [0-9]+ { yylval->int_value = atoi(yytext); return INT_TERM; } [a-zA-Z

C++ classes without .cpp files?

非 Y 不嫁゛ 提交于 2019-12-22 19:21:15
问题 I don't want to write a .cpp file for every simple c++ class. when I write a class definition and declaration in a single .hpp file, the linker complains about multiple definition of member functions which are not implemented inside the body of the class. So I use templates to get rid of linker complaints: // log.hpp file template<typename T> class log_t { private: int m_cnt = 0; public: void log(); }; template<typename T> void log_t<T>::log() { std::cout << ++m_cnt << std::endl; } // some

C++ classes without .cpp files?

北城余情 提交于 2019-12-22 19:20:11
问题 I don't want to write a .cpp file for every simple c++ class. when I write a class definition and declaration in a single .hpp file, the linker complains about multiple definition of member functions which are not implemented inside the body of the class. So I use templates to get rid of linker complaints: // log.hpp file template<typename T> class log_t { private: int m_cnt = 0; public: void log(); }; template<typename T> void log_t<T>::log() { std::cout << ++m_cnt << std::endl; } // some

Condensing Declaration and Implementation into an HPP file

江枫思渺然 提交于 2019-12-22 11:28:28
问题 I've read a few of the articles about the need / applicability / practicality of keeping headers around in C++ but I can't seem to find anywhere a solid reason why / when the above should or should not be done. I'm aware that boost uses .hpp files to deliver template functions to end users without the need for an associated .cpp file, and this thought is partially sourced off browsing through that code. It seems like this would be a convenient way to deliver single file modules of say a new

How to resolve include file names conflicts in GCC?

寵の児 提交于 2019-12-22 11:15:16
问题 I have two header files named string.h in different libraries, they are conflicted with each other and even conflicted with standard C include file of the same name. There is no need to use any string.h except standard one, but I need to include libraries headers paths in GCC search path. Currently I use something like -I /usr/local/include/lib1 -I /usr/local/include/lib2 , but that way I can not include standard C string.h . What is the right way to resolve such conflicts? 回答1: You can

Visual studio: automatically update C++ cpp/header file when the other is changed?

你。 提交于 2019-12-22 08:14:09
问题 For example, if I change the signature in a function in either the header or the cpp, I'd like it to automatically change in the other one. If I add a new function in either, it should appear in both. If I delete a function, it could probably comment out the other one. Manually having to duplicate one's changes seems silly. Some people have mentioned http://www.lazycplusplus.com/ in response to a similar question, but it seems that that's a command line tool which would require saving and

python easy_install: specify directory housing required files

只愿长相守 提交于 2019-12-22 08:10:13
问题 I'm trying to use easy_install to install MySQL-python. It fails almost immediately: _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory It can't find the headers. I have the headers installed, they're just installed from source in /opt. It's obviously not looking there. How do I make it look there? For

Windows <sys/file.h> equivalent

谁都会走 提交于 2019-12-22 06:37:01
问题 Is there a Win32 equivalent to the linux header file? I'm working on a Linux to Windows port (and my first time doing so) and it's failing on this file. 回答1: When writing WIN32API apps you usually #include <windows.h> - that includes most of the Windows API in your application. If you need to cut down on some of those includes, #define WIN32_LEAN_AND_MEAN will wipe out some of the more obscure things from the Windows libraries. What functions are you trying to convert? It'll probably be a

When is a header file required for using a static library?

戏子无情 提交于 2019-12-22 06:30:10
问题 If I create a static library in C++ in Linux such that a ".a" file is produced, how do I (or anyone else) use the library? For example, my library defines a class. I assume that it is not sufficient merely to provide the ".a" file, but also to provide a header file. How do I know what header files must be provided with the ".a" file? For example, do I need to provide all header files that were included anywhere in the code for my library? 回答1: The technical reason for header files is to let