You are here:

C++/Headers and Classes


I'm trying to learn how to use classes in a book on C++ I have (C++ for Dummies). It gives an example in which it defines a class and the variables and functions that go with it, then saves it as a .h file to be included in the main source code file with #include "pen.h" , so that the class can actually be used. I can't get it to work though. I have the class definition saved as a .h in what I think is the same directory as the source code on Apple's XCode. When I attempt to compile/build either one or the other, a single error appears that is very vague and unhelpful: Command /Developer/usr/bing++-4.0 failed with exit code 1. There is also a warning: no rule to process file '$(PROJECT_DIR)/pen.h' of type sourcecode.d.h for architecture i386. My feeling is that my header is somehow not working right and that the two files are not actually "talking" to one another. My code is an exact copy of what's in this book, but I think it was really written with either Code Blocks or Visual C++ as the assumed compilers, so there may be some subtlety I'm missing with the right way to save/organize these files in directories in XCode that I'm doing wrong. Any tips on the proper way to do these things so that it will compile/work?

I use DevCpp mostly, so I may not be able to address your problem. However, I have had some problems when trying to include a header file. You want to make sure that the .h file is in the same folder as your main or calling file, AND that the source file (.h) is compiled within that folder.
Is one of the functions in the pen class "bing" or "bing++"? That would help explain the first error you describe.

What I do when including a header file is make sure it is saved in the same folder as the program that's calling it (although you can also specify a path within the INCLUDE command - eg #include "c:\Programs\C\Classes\pen.h"). Then I compiles it again, and each time it is modified - always before compiling the calling program.

If doing that doesn't solve the issue, you may have to read the XCode manual's error documentation.

Good luck!


All Answers

Answers by Expert:

Ask Experts


Oshi Jager


I can: - help debug code, or make it more efficient - help with concepts, key terms and commands, and object design/inheritance - give suggestions for subroutines or object calls - suggest overall organization techniques and/or data organization I have a fairly good concept of program flow, so if you have ideas, but don't know how to get started... I've had to do a lot of that, and I can help.


Primarily, 36 units in Computer Science at university. Also, I started programming games in C and C++ back when the Commodore 64 was the best game machine out there, and that makes me old... for those of you who don't know the reference. I have intermittently kept up with my programming, so try me out.

As of 2 years ago: Association for Computing Machinery (ACM)

Related classes at Cal State University: - Object Oriented Programming (3 units) [basically C/C++] - Database Design and Implementation (3) [all theory and SQL oriented] - Discrete Mathematics (3) [pure theory] - Computer Organization (3) [cpu functionality and programming] - Data Structures (3) [in C++, but also in general theory] - Computer Architecture (3) [the PC from top to bottom] - Java Programming (3) - Programming Languages (3) [history] - Telecommunications and Networking (3)

©2017 All rights reserved.