473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using one .hh files for multiple .cc files

I will give the general idea here, I am taking a Software development class (im a computer engineering student) and I have run into a road block (could be the coffee and the fact that I am sick) but I want to use 1 .hh file (define.hh) to store a bunch of variable information for about 6 or 7 other files. The problem that I am having is that I am getting multiple defines, how do I get around this problem? (the point of all of this is so that I only have to change one file rather then 5 .hh files)
Mar 25 '07 #1
5 2675
Roonie
99
try
Expand|Select|Wrap|Line Numbers
  1. #ifndef _PICK_A_NAME
  2. #define _PICK_A_NAME
  3. . . .
  4. #endif
Mar 25 '07 #2
try
Expand|Select|Wrap|Line Numbers
  1. #ifndef _PICK_A_NAME
  2. #define _PICK_A_NAME
  3. . . .
  4. #endif
Yeah I dont under stand why that is not working! Here is my code:

#ifndef DEFINE_VAR_HH
#define DEFINE_VAR_HH


//NEEDED INCLUDE FILES
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <math.h>

//OPEN GL INCLUDE FILES FOR MAC
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>



//DEFINE NEEDED CONSTANTS
#define find_max_or_min(testvalue) \
{ \
if (testvalue > paddle_max) { testvalue = paddle_max; } \
else if (testvalue < paddle_min) { testvalue = paddle_min; } \
}

#define PI 3.14159265359

//NEEDED GLOBAL VARIABLES

//SET ALL GAME VARIABLES AND WINDOW SETTINGS
GLfloat screen_length = 400;
GLfloat screen_height = 425;
GLfloat number_of_players = 2;
GLfloat content_space = 25;

//SET VARIABLES FOR WALL DEVELOPMENT
GLfloat NUM_PARTS_WALL = 2;
GLfloat wall_height = 10;
GLfloat wall_length = 370;
GLfloat wall_x_position = 10;
GLfloat wall_border= 10;
GLfloat wall_red = 0.0;
GLfloat wall_blue = 0.0;
GLfloat wall_green = 1.0;

//SET VARIABLES FOR PADDLE DEVELOPMENT
GLfloat paddle_height = 75;
GLfloat paddle_length = 10;
GLfloat paddle_x_position = 0;
GLfloat paddle_y_position = 0;
GLfloat paddle_red = 0.40;
GLfloat paddle_blue = 0.85;
GLfloat paddle_green = 0.0;

//SET VARIABLES FOR BALL DEVELOPMENT
GLfloat ball_radius = 7;
GLfloat ball_x_position = 0;
GLfloat ball_y_position = 0;
GLfloat ball_red = 1;
GLfloat ball_green = 1;
GLfloat ball_blue = 1;

#endif

The game is PONG!
Mar 25 '07 #3
late night bumb
Mar 25 '07 #4
Banfa
9,065 Expert Mod 8TB
Your problem is all your lines of this type

Expand|Select|Wrap|Line Numbers
  1. GLfloat screen_length = 400;
  2.  
This defines and initialises the variable screen_length. Since this is a header file and gets included into many cc files the all get screen_length defined in them and you get a multiple definition error.

In header files you should only declare data not define it. A declaration tells the compiler that the variable exists somewhere in the program (it is the linkers job to work out where) where as a definition actually creates the variable.

You can not initialise in a declaration and you show it is a declaration by putting extern in front of it. So your header file should contain

Expand|Select|Wrap|Line Numbers
  1. extern GLfloat screen_length;
  2.  
to declare the variable screen_length. There is more to do, if you only do this then you will have declared the variable in all your cc files but defined it no where. You will get an unresolved external symbol in the linker.

In 1 cc file (some people create 1 specially for this purpose an some just choose an existing cc file) you have to add you definitions so you would put

Expand|Select|Wrap|Line Numbers
  1. GLfloat screen_length = 400;
  2.  
into a c file. The linker will link the variable declared in all the other cc files to the 1 definied in this 1 file.


Obviously you will have to do this for all the variables you have declared.
Mar 25 '07 #5
That worked, thanks for the help! Great website, how you guys will be getting all my coding problems haha
Mar 25 '07 #6

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

Similar topics

0
by: Dominik | last post by:
I am writing application which must download multiple files simultaneous. Initially I wanted to use multiple threads to achieve this task but later I heard that Net is "using" separate thread from...
6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
9
by: 101 | last post by:
Taking a course on SQL. They are saying you can get better performance by having multiple files for a group. They then graphically show an example of "Primary" with multiple data files. I have...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
3
by: codabill | last post by:
Can someone please refer me to books, articles, websites where I can obtain information on how to set up VS2003 for team development. I am a project manager for a non-trivial military software...
1
by: PK9 | last post by:
I'm building a windows app using C#. The goal is to merge portions of multiple xml files into one. I currently have an .xsl stylesheet that pulls in the required sections of multiple xml files...
36
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same...
0
by: pbd22 | last post by:
Hi. I am having a really tough time here and would appreciate some help. i am using an iFrame to pass a url string of files to upload to server. on the client i have created a multiple...
7
by: Pete | last post by:
I need to import multiple tab delimited files for which I do not have the formats. All files have column headers in the the line. The files must be dynamic. The only common value is that the...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.