header-files

External dependencies / Header files

In a windows MSVC6.0 compiler, if there is a workspace with one project in it, what files would be in the Header Files folder and what files would be in the External Dependencies folder? I thought those files which are explicitly included (#include <*.h> are to be in the Header Files folder and thsoe which are in turn included by add...

C++ Header files - Confused!

game.h needs: - packet.h - socket.h server.h needs: - socket.h socket.h needs: - game.h The problem comes when I try to include socket.h into game.h, because socket.h has game.h included already. How do I solve these kind of problems? ...

C++ namespace and include

Why do we need both using namespace and include directives in C++ programs ? For example, #include <iostream> using namespace std; int main() { cout << "Hello world"; } Why is it not enough to just have #include or just have "using namespace std" and get rid of the other ? (I am think of an analogy with Java, import java.net.* ...

Best practices for use of C++ header files

I have the following doubts on header files usage. 1 - Include guards placing after comments /* Copyright Note and licence information (multiple lines) */ #ifndef FOO_H #define FOO_H // Header file contents #endif Herb Sutter says in his "C++ coding standards" book that code like the above is problematic. He is saying the "#ifndef" s...

Writing function definition in header files - C++

I have a class which has many small functons. By small functions, I mean functions that doesn't do any processing but just return a literal value. Something like string Foo::method() const{ return "A"; } I have created a header file "Foo.h" and source file "Foo.cpp". But since the function is very small, I am thinking about puttin...

C++ Header implementing a C# Interface

Hi. Basically I want to know if it is possible to implement a C++ header from a C# interface, because I can't make it work. Example: C# Interface: public interface A { void M( ushort u ); } C++ header: public ref class B : A { void M( unsigned short u ); } Returns "Error C3766". Thanks in advance. ...

Separate header files for concrete classes - C++

Background I have an abstract class, something like class IConverter{ public: virtual void DoConvertion() = 0; }; There will be many concrete classes which just implements DoConvertion method. class TextConverter : public IConverter{ public: virtual void DoConvertion(){ // my code goes here } }; class ...

Header Files in Multiple Directories: Best Practices

I'm a C Newb I write lots of code in dynamic languages (javascript, python, haskell, etc.), but I'm now learning C for graduate school and I have no idea what I'm doing. The Problem Originally I was building all my source in one directory using a makefile, which has worked rather well. However, my project is growing and I would like ...

rules for inclusion in header files when using type in typedef

if I create typedef double (MyClass::*MemFuncGetter)(); in a header file, do I need to include "MyClass.h" or would forward declaring suffice? Header file: #ifndef _TEST_ #define _TEST_ #include "MyClass.h" //do I need this? //or I can just say class MyClass; typedef double (MyClass::*MemFuncGetter)(); #endif What are the li...

Is using .h as a header for a c++ file wrong?

Is using .h as a header for a c++ file wrong? I see it all over the place, especially with code written in the "C style". I noticed that Emacs always selects C highlighting style for a .h header, but c++ for hpp or hh. Is it actually "wrong" to label your headers .h or is it just something which annoys me? EDIT: There is a good (is...

g++ header included: still doesn't find definition

Good evening :) I'm playing around with g++ and makefiles. I've gotten to this point: foo.h: #ifndef _FOO_H_ #define _FOO_H_ #include "bar.h" class foo { private: bar something; public: bool start(); bool stop(); }; #endif // _FOO_H_ Foo.h is eventually included in my main cpp file so I can set things in motion by cal...

How does inclusion of header file happen?

I have a plain C code with *.c and *.h files in the workspace. I have a header file 1.h declaring some structure as struct my1 { int a; .. .. }my_t; But when i try to declare a variable of type struct my1 in another header file 2.h as follows:- struct my1 variable1; It gives error at this declaration point. Looks like my1 is und...

Should C++ eliminate header files?

Many languages, such as Java, C#, do not separate declaration from implementation. C# has a concept of partial class, but implementation and declaration still remain in the same file. Why doesn't C++ have the same model? Is it more practical to have header files? I am referring to current and upcoming versions of C++ standard. ...

Cost of Including Header Files in Objective-C

This may seem like a really stupid question, but what is the cost of including (actually, calling #import) a header file in Objective-C? I get tired of constantly including the same headers in various locations, so I decided to simply create a GlobalReferences.h file that includes several commonly-referenced headers. Is there any apprec...

Why does my .push_back() give me an error? (C++)

I initialized a vector of pointers called "antiviral_data", and am able to use antiviral_data.push_back without problems. But when I try to do the same thing with "viral_data" I get an error, because the compiler thinks I am redeclaring "viral_data": vector<virus*> viral_data; vector<virus*>::iterator vI; viral_data.push_back(new X1(9, ...

Is reducing number of cpp translation units a good idea?

I find that if there are a lot of classes the compilation time is dramatically increased when I use one *.h and one *.cpp file per class. I already use precompiled headers and incremental linking, but still the compile time is very long (yes I use boost ;) So I came up with the following trick: defined *.cpp files as non-compilable de...

Making references to classes you havn't #include'd (C++)

I'm playing around with Box2D for fun right now, and after getting the hang of some of the concepts I decided to make my own test for the test bed (Box2D comes with a set of examples and has a simple extendable Test class for making your own tests). I started by grabbing one of the other tests, ripping out everything but the function sig...

C project structure - header-per-module vs. one big header

I've worked with a number of C projects during my programming career and the header file structures usually fall into one of these two patterns: One header file containing all function prototypes One .h file for each .c file, containing prototypes for the functions defined in that module only. The advantages of option 2 are obvious t...

How can I parse a C header file with Perl?

Hi, I have a header file in which there is a large struct. I need to read this structure using some program and make some operations on each member of the structure and write them back. For example I have some structure like const BYTE Some_Idx[] = { 4,7,10,15,17,19,24,29, 31,32,35,45,49,51,52,54, 55,58,60,64,65,66,67,69, 70,72,76,7...

Coding C++ without headers, best practices?

When i first learned c++, I had already coded in many other languages prior to it, which made the prospect of headers really depressing. So far, my solution to coding without header files in c++ has been far from optimal, limiting what I can do in the language. Is there any way to not have to write function declarations twice (headers) ...