header-files

C++ - Defining class template (header/source file)

大城市里の小女人 提交于 2019-12-06 13:29:46
问题 I want to create a processor in voreen (like this one .cpp | .h) porting this OTB-Application: http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx I have coded almost all the parameters into properties, etc but.. If you look at like 376, you'll see a class template of FloatVectorImageType::SizeType, a typedef type. Im not familiar with c++ templates so my first question was where should I put this template's implementation, in the .cpp or .h file of

C++ classes without .cpp files?

不问归期 提交于 2019-12-06 12:37:14
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 random type (int) typedef log_t<int> log; And then I can simply use log class in multiple .cpp files

Xcode 4.3.3 can't find any header files

空扰寡人 提交于 2019-12-06 09:22:10
Up until now I've managed to get Xcode to link to the Gnu Scientific Libraries (GSL) which I've installed under /usr/local/lib/ and with header files under /usr/local/include. Under "Build Phases" > "Link Binary With Libraries" I had added libgsl.a etc. Today, Xcode gives an error message claiming it can't find header files. For example #include <stdio.h> #include <gsl/gsl_matrix.h> int main(int argc, const char * argv[]) { printf("Hello, World!\n"); return 0; } results in 'gsl/gsl_matrix.h' file not found. I've tried to change the User Header Search path to no avail. Using gcc main.c -lgsl

Why does OpenBSD's G++ make system headers default to C linkage?

て烟熏妆下的殇ゞ 提交于 2019-12-06 07:28:18
I am porting some code to OpenBSD 5.0 and I ran into this very strange problem. My build settings use -isystem /usr/local/include . It is hard to remember but I believe I did that to avoid masses of compiler warnings from my use of -Wall on system types -- like BSD -- that install Boost to /usr/local/include . This seems to work great on FreeBSD. So take the following program: #include <boost/array.hpp> int main() { return 0; } Then build it with: c++ -O2 -pipe -isystem /usr/local/include -std=c++98 -o test test.cxx On OpenBSD I discovered that I get: In file included from /usr/include/g++

Condensing Declaration and Implementation into an HPP file

五迷三道 提交于 2019-12-06 05:55:10
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 Wt or Qt widget (still sticking to the one class per .h convention). However are there any negative

Is C compiler able to optimize across object file?

泪湿孤枕 提交于 2019-12-06 05:09:00
I'm considering between header-only vs. header&source design. I'm not sure if the header&source allows compiler to optimize across object files and across linkage ? such as inlining optimization ? Header files and source files typically compiled as a single translation unit (since headers are included in the source files). So, that won't be an issue (unless you have a peculiar environment where headers are compiled separately). GCC does support optimizations across different translation units. See Link Time Optimization . See the -flto option's documentation for details: -flto[=n] This option

How to class-dump AppStore app

我是研究僧i 提交于 2019-12-06 03:47:25
问题 I installed "Class Dump" from Cydia to get application header files. But there is a problem. I can use class-dump in default app. For example, I ran this command: class-dump -H /Applications/MobileSafari.app/MobileSafari -o /Headers/safari and could get header files in "/Headers/safari/". But AppStore app, for example, I ran this command: class-dump -H /var/mobile/Applications/BFF...../Dropbox.app/Dropbox -o /Headers/dropbox and terminal works, but garbled characters appeared (ScreenShot) and

Should '#include' and 'using' statements be repeated in both header and implementation files (C++)?

岁酱吖の 提交于 2019-12-06 02:13:47
问题 I'm fairly new to C++, but my understanding is that a #include statement will essentially just dump the contents of the #included file into the location of that statement. This means that if I have a number of '#include' and 'using' statements in my header file, my implementation file can just #include the header file, and the compiler won't mind if I don't repeat the other statements. What about people though? My main concern is that if I don't repeat the '#include', 'using', and also

How to define function in other source file:C++ CodeBlocks

不问归期 提交于 2019-12-06 01:48:19
问题 I am trying to separate my functions in another source file. But i am getting error that multiple definition on add function. Main source file Main.cpp #include<iostream> #include "myHeader.h" using namespace std; int main() { int result = add(1,2); } Header file "myHeader.h" #include "calc.cpp" int add(int, int); Other Source file "calc.cpp" int add(int a, int b) { return a+b; } 回答1: Don't include calc.cpp from myHeader.h . Except for that one line, your example is right as far as headers go

What is the difference between #import and #include in C?

喜夏-厌秋 提交于 2019-12-06 00:29:09
I've read up a bit on preprocessor directives and I've seen #import being used a few times in C programs. I'm not sure what the difference is between them, some sites have said that #include is only used for header files and #import is used more in Java and is deprecated in C. If that's the case, why do some programs still use #import and how exactly is it different from #include? Also, I've used #import in a few of my C programs and it seems to work fine and do the same thing as #include. This is well-explained in the Gnu CPP (C preprocessor) manual, although the behaviour is the same in