header-files

What mean file with extension “h.in”?

狂风中的少年 提交于 2019-11-28 20:56:23
问题 I am studying the C language, and I saw a new extension that I had not seen before. What do files with the extension like library.h.in mean? Is it as the simple header with extension ".h"? What's the difference? 回答1: These files are usually the input for autoconf which will generate final .h files. Here's an example from PCRE: #define PCRE_MAJOR @PCRE_MAJOR@ #define PCRE_MINOR @PCRE_MINOR@ #define PCRE_PRERELEASE @PCRE_PRERELEASE@ #define PCRE_DATE @PCRE_DATE@ Autoconf will replace all

Initializing Constant Static Array In Header File

删除回忆录丶 提交于 2019-11-28 19:42:21
问题 I have just found out that the following is not valid. //Header File class test { const static char array[] = { '1', '2', '3' }; }; Where is the best place to initialize this? 回答1: The best place would be in a source file // Header file class test { const static char array[]; }; // Source file const char test::array[] = {'1','2','3'}; You can initialize integer types in the class declaration like you tried to do; all other types have to be initialized outside the class declaration, and only

Header files inclusion / Forward declaration

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 19:19:15
问题 In my C++ project when do I have to use inclusion ( #include "myclass.h" ) of header files? And when do I have to use forward declaration of the class ( class CMyClass; )? 回答1: As a rule try the forward declaration first. This will reduce compile times etc. If that doesn't compile go for the #include . You have to go for the #include if you need to do any of the following: Access a member or function of the class. Use pointer arithmetic. Use sizeof. Any RTTI information. new / delete , copy

When are header-only libraries acceptable?

安稳与你 提交于 2019-11-28 19:14:07
Personally, I quite like header-only libraries, but there are claims they cause code bloat due to over-inlining (as well as the other obvious problem of longer compile times). I was wondering, how much truth is there to these claims (the one about bloat)? Furthermore, are the costs 'justified'? (Obviously there are unavoidable cases such as when it's a library implemented purely or mostly with templates, however I'm more interested in the case where there's actually a choice available.) I know there's no hard and fast rule, guideline, etc as far as stuff like this goes, but I'm just trying to

Why shouldn't I put “using namespace std” in a header?

蓝咒 提交于 2019-11-28 14:32:24
Someone once hinted that doing this in a header file is not advised: using namespace std; Why is it not advised? Could it cause linker errors like this: (linewrapped for convenience) error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >:: ~basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in tools.lib(Exception.obj) Because it forces anyone who uses your header file to bring the std namespace into global scope

“Multiple definition” when using (mock) header files for templates

大兔子大兔子 提交于 2019-11-28 14:13:46
I am aware that definitions of C++ templated functions have to be placed in header files. However, for reasons of improved readability and structure of a (potentially) big library I am making, I separated the declarations from the implementations, into "mock" headers (which #include the implementation files, quite like this structure of files). Note that am I am aware that the implementation of templated functions must be included at compile time, and I am doing that . In short, I have a "multiple definition" error when I add a non-templated function declaration into the implementation file .

Header files won't work in C [closed]

大憨熊 提交于 2019-11-28 13:09:59
I'm using Dev-CPP, (but programming in C), and the header files won't work. I've gone to compiler option; directories; c inludes and checked the directory is correct, and it is. The include files are stored in C:\Dev-Cpp\include and that's where it's set to receive them. For example: #include <conio.h> int main(int argc, char *argv[]) { textcolor(1); printf("Why won't header files work? \n"); system("PAUSE"); return 0; } I've tried with several other header files, but they also don't work. I'm sure the answer is really obvious, but I'm clearly too stupid to fix this. I'm also using MinGW as

function … has already a body & function template has already been defined

匆匆过客 提交于 2019-11-28 13:03:55
问题 I have this header file: Utility.h: #pragma once #include <fstream> #include <iostream> #include <string> #include <vector> #include <Windows.h> using namespace std; template<std::size_t> struct int_ {}; template <class Tuple, size_t Pos> std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>); struct Timer { public: Timer(); void start(); double getMilliSec(); private: LARGE_INTEGER frequency; // ticks per second LARGE_INTEGER t1, t2; // ticks }; //... #include "Utility.cpp"

include stdafx.h in header or source file?

a 夏天 提交于 2019-11-28 11:59:44
I have a header file called stdafx.h and this one is precompiled of course. I've read that I should include these files into my .cpp files, but some of these statements are already needed in the header file coming with that. Should I add the stdafx into my header or into my cpp? I thought it was good practise to put it into the header, but I seem to be obliged to put it into the header instead. Example: stdafx contains freeglut. my class header file has an attribute of GLenum. Should I include the stdafx into the .h of the class? stdafx.h should be the first include in EVERY cpp file in your

javac “no source files” when using -h option

给你一囗甜甜゛ 提交于 2019-11-28 11:24:39
I'm trying to experiment with using the JNI and JDK 9. I have a class NativeTest.java that looks like this: public class NativeTest { static { System.loadLibrary("hello"); } private native void sayHello(); public static void main(String[] args) { new NativeTest().sayHello(); } } I compile the class, then use javah NativeTest to generate the header file. Upon issuing javah , I get this warning: Warning: The javah tool is planned to be removed in the next major JDK release. The tool has been superseded by the '-h' option added to javac in JDK 8. Users are recommended to migrate to using the