header-files

C++: Namespaces — How to use in header and source files correctly?

巧了我就是萌 提交于 2019-12-31 07:59:25
问题 Consider a pair of two source files: an interface declaration file ( *.h or *.hpp ) and its implementation file ( *.cpp ). Let the *.h file be like the following: namespace MyNamespace { class MyClass { public: int foo(); }; } I have seen two different practices for using namespaces in source files: *.cpp showing practice #1: #include "MyClass.h" using namespace MyNamespace; int MyClass::foo() { ... } *.cpp showing practice #2: #include "MyClass.h" namespace MyNamespace { int MyClass::foo() {

C program cannot find function which included in header file

▼魔方 西西 提交于 2019-12-31 04:40:14
问题 I made program like this. 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include "libavformat/avformat.h" 5 6 int main (int argc, char* argv[]){ 7 av_register_all(); 8 return 0; 9 } My header file located in root@ubuntu:/home/juneyoungoh/getDuration# find / -name "avformat.h" /root/ffmpeg/libavformat/avformat.h /usr/local/include/libavformat/avformat.h then I run with gcc getDuration.c , but I show message like below. root@ubuntu:/home/juneyoungoh/getDuration# gcc

Explanation of Header Pixel in GIMP created C Header File of an XPM image

对着背影说爱祢 提交于 2019-12-31 01:25:53
问题 In GIMP, you're able to save an image as a C header file. I did so with an XPM file, which looks like the image below: If I were to save the XPM image as a C header file, GIMP will output this C header file. In order to process each pixel of the given image data, the header pixel is called repeatedly. What I don't understand is what the header pixel does to process the data in the first place. #define HEADER_PIXEL(data,pixel) {\ pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \

Why including same headers in multiple cpp files and then their compilation works? [duplicate]

混江龙づ霸主 提交于 2019-12-30 13:41:26
问题 This question already has an answer here : One definition rule and different class definitions in two translation units (1 answer) Closed 6 years ago . For example I have 2 cpp files: f1.cpp and f2.cpp, and also a header file: xxx.h. f1.cpp has the following source code: #include <iostream> #include "xxx.h" using namespace std; int main () { rect rplace; polar pplace; cout<<"Enter the x and y values: "; while (cin>>rplace.x>>rplace.y) { pplace=rect_to_polar(rplace); show_polar(pplace); cout<<

Why including same headers in multiple cpp files and then their compilation works? [duplicate]

吃可爱长大的小学妹 提交于 2019-12-30 13:41:10
问题 This question already has an answer here : One definition rule and different class definitions in two translation units (1 answer) Closed 6 years ago . For example I have 2 cpp files: f1.cpp and f2.cpp, and also a header file: xxx.h. f1.cpp has the following source code: #include <iostream> #include "xxx.h" using namespace std; int main () { rect rplace; polar pplace; cout<<"Enter the x and y values: "; while (cin>>rplace.x>>rplace.y) { pplace=rect_to_polar(rplace); show_polar(pplace); cout<<

How to install/locate R.h and Rmath.h header files?

旧巷老猫 提交于 2019-12-30 08:14:48
问题 I am trying to compile some C code (called rand_beta) in terminal which contains the lines to include R.h and Rmath.h header files using gcc -o rand_beta rand_beta.c so I can then call the code from within R. However, I get the error messages: rand_beta.c:1:15: error: R.h: No such file or directory rand_beta.c:2:19: error: Rmath.h: No such file or directory It seems that these header files which should come installed with R are not on my system. Can someone guide me as to how I can get my

How to make Makefile recompile when a header file is changed?

别来无恙 提交于 2019-12-30 03:36:05
问题 I have written a Makefile to compile an openCV program on OSX (more general in Unix systems). The code has a header named constants.hpp where some constants are defined. I would like to make the Makefile recompile the program when this header file changes because the values of the constants in it change the program behavior. My Makefile is the following CPP = g++ CPPFLAGS = -std=c++11 all: main.o main.o: main.cpp $(CPP) $^ $(CPPFLAGS) -o $@ Searching around I tried to define after CPPFLAGS

How to create two classes in C++ which use each other as data?

删除回忆录丶 提交于 2019-12-27 16:51:05
问题 I'm looking to create two classes, each of which contains an object of the other class type. How can I do this? If I can't do this, is there a work-around, like having each class contain a pointer to the other class type? Thanks! Here's what I have: File: bar.h #ifndef BAR_H #define BAR_H #include "foo.h" class bar { public: foo getFoo(); protected: foo f; }; #endif File: foo.h #ifndef FOO_H #define FOO_H #include "bar.h" class foo { public: bar getBar(); protected: bar b; }; #endif File:

How to create two classes in C++ which use each other as data?

谁都会走 提交于 2019-12-27 16:47:11
问题 I'm looking to create two classes, each of which contains an object of the other class type. How can I do this? If I can't do this, is there a work-around, like having each class contain a pointer to the other class type? Thanks! Here's what I have: File: bar.h #ifndef BAR_H #define BAR_H #include "foo.h" class bar { public: foo getFoo(); protected: foo f; }; #endif File: foo.h #ifndef FOO_H #define FOO_H #include "bar.h" class foo { public: bar getBar(); protected: bar b; }; #endif File:

multiple definition in header file

天大地大妈咪最大 提交于 2019-12-27 12:17:50
问题 Given this code sample: complex.h : #ifndef COMPLEX_H #define COMPLEX_H #include <iostream> class Complex { public: Complex(float Real, float Imaginary); float real() const { return m_Real; }; private: friend std::ostream& operator<<(std::ostream& o, const Complex& Cplx); float m_Real; float m_Imaginary; }; std::ostream& operator<<(std::ostream& o, const Complex& Cplx) { return o << Cplx.m_Real << " i" << Cplx.m_Imaginary; } #endif // COMPLEX_H complex.cpp : #include "complex.h" Complex: