header-files

C++ Does not name to a type

∥☆過路亽.° 提交于 2019-11-29 18:07:35
This might be an easy question, but I cannot figure out why the compiler it's giving me this error. I have two classes. Agent and Environment. WHen I try to add an object of type Agent in my Environment class I get Agent does not name to a type error. I am including Agent.h in my Environment.h class #ifndef AGENT_H_INCLUDED #define AGENT_H_INCLUDED #include <vector> #include <iostream> #include "Environment.h" using namespace std; class Agent{ public: Agent(bool s); vector<int> getPercept(); void setPercept(vector<int> p); void goForward(); void turnRight(); void turnLeft(); void clean(); void

including a header file twice in c++

六眼飞鱼酱① 提交于 2019-11-29 17:26:41
问题 What happens if I include iostream or any other header file twice in my file? I know the compiler does not throw error. Will the code gets added twice or what happens internally? What actually happens when we include a header file ? 回答1: Include guard prevents the content of the file from being actually seen twice by the compiler. Include guard is basically a set of preprocessor's conditional directives at the beginning and end of a header file: #ifndef SOME_STRING_H #define SOME_STRING_H //.

Error “C++ requires a type specifier for all declarations whilst defining methods”

白昼怎懂夜的黑 提交于 2019-11-29 16:59:43
问题 I'm relatively new to C++ (so try and keep answers simple please!), and I can't understand why I get the error: C++ requires a type specifier for all declarations whilst defining methods. I am trying to write a simple program to read a text file line by line, store the values into an array. However I am encountering an issue when trying to declare methods in my .cpp file. Please find code below. StringList.h #ifndef StringListH #define StringListH #include <vector> #include <string> class

Expose only required information without including unnecessary header files

本小妞迷上赌 提交于 2019-11-29 16:09:40
I want a process to expose a structure of a message, so it can be used by other processes receiving it. However, this structure includes types of arguments which are defined in other header files, which themselves include a bunch of other header files. typedef struct sfp_info_s { int port; char platform_id[50]; sff_eeprom_t sff_type; char status_str[50]; sff_dom_t sff_dom; }sfp_info_t; sff_eeprom_t is defined in a header file named : sff_db.h and this file itself includes other files : #ifndef __SFF_SFF_H__ #define __SFF_SFF_H__ #include <sff/sff_config.h> #include <AIM/aim_pvs.h> #include

multiple definition error c++

戏子无情 提交于 2019-11-29 15:43:06
问题 My 'Headers.h' file includes basic c++ Headers #include <iostream> #include <cstring> // and many header files. wrote a function definition for file exist check and saved it in 'common_utility.h' - ifFileExist() common_utility.h bool ifFileExist() { // ... My code } Wrote code for Class A classA.h class A { // Contains class A Declarations. }; classA.cpp // Contains #include "Headers.h" #include "common_utility.h" #include "classA.h" // class A Method definition Wrote Code for Class B I am

how to include header files more clearly in C++

限于喜欢 提交于 2019-11-29 15:38:18
In C++, I have some header files such as: Base.h , and some classes using Base.h : //OtherBase1.h #include "Base.h" class OtherBase1{ // something goes here }; //OtherBase2.h #include "Base.h" class OtherBase2{ // something goes here }; And in main.cpp , I can only use one of those two OtherBase classes because of duplicate header. If I want to use both classes, in OtherBase2.h I have to #include "OtherBase1.h" instead of #include "Base.h" . Sometimes, I just want to use OtherBase2.h and not OtherBase1.h , so I think it's really weird to include OtherBase1.h in OtherBase2.h . What do I do to

dos.h for Linux?

一世执手 提交于 2019-11-29 14:22:15
I have a C program which contains #include <dos.h> header. It shows a compile time error. I know that the dos.h header file is not valid in Linux. Is there any other equivalent header for dos.h in Linux? dos.h header file is interface to the DOS operating system. They are not portable to operating systems other than DOS (means not works in Linux). Which functionality in dos.h you are going to use? Basile Starynkevitch Linux is a Posix/Unix like system, so you should learn the system calls and facilities that you can use. Read the advanced unix programming book (or some equivalent; AUP is

How to include C++ 17 headers with g++ 6.2.0 with -std=c++17 (optional, any, string_view, variant)

隐身守侯 提交于 2019-11-29 13:55:07
std::optional is in C++ 17, where it was std::experimental::optional before. I tried compiling a file which included <optional> , with the command: g++ -std=c++17 <filename>.cpp (in the Bash terminal). I get the following error: <filename>.cpp:5:20 fatal error: optional: No such file or directory #include <optional> ^ compilation terminated But I can #include <experimental/optional> just fine. Am I missing some header files? How can I include the optional header? I also can't include <any> , <string_view> or <variant> , getting the same error. You can't. GCC 6.2's support for C++17 is

How to use namespace across several files

喜欢而已 提交于 2019-11-29 13:23:17
I notice that C++'s std namespace is spread across several files (like in vector , string , iostream , etc.). How can I accomplish the same thing in my programs? Do I simply declare the same namespace in each individual header file, so that it's something like: a.h namespace something { class A {}; } b.h #include "a.h" namespace something { class B : public A {}; } And then in, say, main.cpp , I would just include "b.h" and "a.h" and then using namespace something; to use the two classes? Yes, that is exactly how to do it. 来源: https://stackoverflow.com/questions/4637811/how-to-use-namespace

gem install cannot find a header file

自作多情 提交于 2019-11-29 12:51:45
Following along the github README for talib_ruby: sudo port install ta-lib Complete. Next is where the trouble begins. sudo env ARCHFLAGS="-arch PLATFORM" gem install talib_ruby -- --with-talib-include=ABSOLUTE_PATH_TO_TALIB_HEADERS --with-talib-lib=ABSOLUTE_PATH_TO_TALIB_LIBS This install fails I believe because apparently it cannot find the ta_abstract.h file talib.c:2:25: error: ta_abstract.h: No such file or directory . . . many more errors I have included in my .bash_profile file the following: export ABSOLUTE_PATH_TO_TALIB_HEADERS=/opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local