By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,438 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

Include-path in C++

P: 5
Hi,

I have gathered all my constants in one “.h” file and I want to use them in my classes, which are all in a directory called “Classes”. The problem is about the scope. The “Constants.h” is at the same level as “Classes”’s directory, so that my classes do not see “Constants.h”:

The case is like this:

My_project\Classes\class_a.h
My_project \Classes\class_a.cpp
My_project\Constants.h

What include-path should I use for my classes to have access to the constants?

In addition, must my constants be static?

Thanks,
FloatingPoint
Jun 21 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
The path you need to add is either

a relative path

..\

or as an absolute path

\<PathToMyProject>\My_project\

But I think you may have a problem in your code this statement gives it away

In addition, must my constants be static?
If you have declared your constants as

Expand|Select|Wrap|Line Numbers
  1. const float PI=3.1416;
in your Constants.h then you have made a mistake.

You should have them as

Expand|Select|Wrap|Line Numbers
  1. extern const float PI;
in the header file and then in a cpp file (may be constants.cpp) you should have

Expand|Select|Wrap|Line Numbers
  1. const float PI=3.1416;
If you just added static to all the declarations all that will happen is that even single cpp file they are included into will have their own copy of the constants and you will be using much more data than required (particularly important in an embedded application).

Never declare variables in a header.
Jun 21 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.