header-files

What is a guard block for a header file in C++?

∥☆過路亽.° 提交于 2021-02-20 11:32:21
问题 I'm trying to make a C++ class using the Code::Blocks IDE and there is a field called "Guard block." I've done a search and haven't been able to find any useful information. What is this field for? Thanks. 回答1: Guard blocks are used to protect against the inclusion of a header file multiple times by the same compilation unit (c++ file). They look something like this: // Foo.h #ifndef INCLUDE_FILE_NAME_HERE_H_ #define INCLUDE_FILE_NAME_HERE_H_ class Foo { }; #endif If you include the same file

How to avoid variable/function conflicts from two libraries in C++

一笑奈何 提交于 2021-02-18 11:44:17
问题 I have similar scenario as explained below: I have one header file first.h It has a function : char* getName(); and associated cpp file first.cpp having function definition char* getName(){return "first";} and the second header file second.h it has the function: char* getName(); associated cpp file second.cpp having function definition char* getName(){return "second";} Now there is a main() function: #include "first.h" #include "second.h" int main(){ return 0; } when I include those .h files,

Avoiding repetitive sub-class definitions in C++

感情迁移 提交于 2021-02-11 08:58:30
问题 I am new to C++ classes, and I have a question about defining multiple sub-classes of an abstract type/interface which would have identical definitions. Take the following example which might appear in a header file with 3 sub-classes: class Animal { private: int a; int b; public: explicit Animal(int a) {} virtual Animal* getFriend() = 0; virtual bool walk() = 0; virtual bool talk() = 0; virtual bool someFunction() = 0; virtual bool someOtherFunction() = 0; // ... many more functions } class

VXWorks adding functions to header files

夙愿已清 提交于 2021-02-10 22:16:57
问题 I'm trying to add my own function to jobQueueLib and step through the lines of code for that, or any of the functions there (which are all EXTERNs). Stepping through the .h function call goes straight to assembly if I don't put #include <jobQueueLib.h>, which is referring to vxworks-6.9/target/h/wrn/coreip/jobQueueLib.h With the include added, stepping into a same existing function causes a segmentation violation. UPDATE: My issue is C, downloadable kernel module project build, or component

Include multiple header-files at once with only one #include-expression?

南楼画角 提交于 2021-02-08 13:33:08
问题 Is there any expression possible for the syntax to include multiple headers at once, with no need to write the "#include"-expression for each file new? Like, for example: #include <stdio.h>, <stdlib.h>, <curses.h>, <string.h> /* Dummy-Expression 1. */ OR #include <stdio.h> <stdlib.h> <curses.h> <string.h> /* Dummy-Expression 2. */ Question is for C AND C++. 回答1: No, there is no way to do this. You have to type out (or copy) each #include to its own line, like this: #include <stdio.h> #include

CMake build error with added header file - fatal error: file not found

别等时光非礼了梦想. 提交于 2021-02-07 18:17:58
问题 I used CMake to build C++ source files in Ubuntu 14.04. I has a main source file. This includes a header file, which contains a function in another source file. My main source file is DisplayImage.cpp, and my header file is Camera.h with a source file Camera.cpp. Every file is located in one folder. And I have a CmakeLists.txt: cmake_minimum_required(VERSION 2.8) project( DisplayImage ) find_package( OpenCV REQUIRED ) add_executable( DisplayImage DisplayImage.cpp Camera.cpp ) target_link

Collect common includes in a single file - good practice?

自闭症网瘾萝莉.ら 提交于 2021-02-07 12:46:13
问题 I am trying to learn how to deal with a lot of includes, and still keep my code tidy. I am programming a Qt application and I have put files commonly used (and that doesn't change) in a file called "Util.h". Util.h #pragma once #include <Core/IObserver.h> #include <Core/Math.h> #include <QAction> #include <QDockWidget.h> #include <QFileDialog> #include <QGraphicsBlurEffect> #include <QLabel.h> #include <QMainWindow.h> #include <QMenu.h> #include <QMessageBox.h> #include <QShortcut.h> #include

Are there any performance implications to including every header?

会有一股神秘感。 提交于 2021-02-07 11:19:15
问题 Lets say I want to use hex() function. I know it is defined in <ios> header and I also know that it is included in <iostream> header. The difference is that in <iostream> are much more functions and other stuff I don't need. From a performance stand-point, should I care about including/defining less functions, classes etc. than more? 回答1: There is no run time performance hit. However, there could be excessive compile time hit if tons of unnecessary headers are included. Also, when this is

YCM does not find my headers?

半城伤御伤魂 提交于 2021-02-07 05:38:25
问题 I have the following folder structure: . ├── include │ └── ctset │ ├── hashtable.h │ └── set.h └── src └── hashtable └── hashtable.c And in hashtable.c the include #include "ctset/hashtable.h" , but YCM keeps telling me that it doesn't know the types I defined in the header and use in the source. My .ycm_extra_conf.py is almost the default one with some adjustments: # This file is NOT licensed under the GPLv3, which is the license for the rest # of YouCompleteMe. # # Here's the license text

YCM does not find my headers?

南楼画角 提交于 2021-02-07 05:38:06
问题 I have the following folder structure: . ├── include │ └── ctset │ ├── hashtable.h │ └── set.h └── src └── hashtable └── hashtable.c And in hashtable.c the include #include "ctset/hashtable.h" , but YCM keeps telling me that it doesn't know the types I defined in the header and use in the source. My .ycm_extra_conf.py is almost the default one with some adjustments: # This file is NOT licensed under the GPLv3, which is the license for the rest # of YouCompleteMe. # # Here's the license text