|
-
Feb 3rd, 2001, 05:40 AM
#1
Thread Starter
Hyperactive Member
I was writting an small program and then I had to change the color rapidly, I thought maybe it is possible to write a big source file with lots of functions and each function be one color and then call the functions from another source file in the project whenever I need it. In this way I can include this source file in all of my projects and I can use it whenever I need to change the coloring.
If there is a way I appreciate it if you tell me.
Thanks in advance
===========================
Kourosh Gonabadi
VB Programmer 
C++ Newbie 
Graphic Designer
===========================
-
Feb 3rd, 2001, 11:56 AM
#2
PowerPoster
why don't you just make a header file, like colorfunctions.h?
-
Feb 3rd, 2001, 12:47 PM
#3
Monday Morning Lunatic
sail has the right idea here, but you need a source file to go with it:
colours.h
Code:
#ifndef __COLOURS_H__
#define __COLOURS_H__
void functionA();
int functionB(int);
long OtherFunction(char*);
#endif // __COLOURS_H__
colours.cpp
Code:
#include "colours.h"
// put the functions here
main.cpp
Code:
#include <iostream.h>
#include "colours.h" /* important - quotes not angle-brackets! */
void main() {
OtherFunction(...);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 3rd, 2001, 01:53 PM
#4
How does the .h file know where to look for the functions if you haven't included the .cpp file with it?
-
Feb 3rd, 2001, 05:55 PM
#5
Monday Morning Lunatic
Because it's not the compiler's job.
The .h file is for the compiler, and tells it to expect these functions. The compiler compiles that .cpp file to an .obj file. The linker then matches the dependent functions in each .obj file when it creates the final .exe 
Simple really
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 3rd, 2001, 06:22 PM
#6
Cool
-
Feb 4th, 2001, 01:07 AM
#7
Thread Starter
Hyperactive Member
Thanks alot for the replies, I am going to try this approach but I probably would fail. Anyhow thanks alot again.
===========================
Kourosh Gonabadi
VB Programmer 
C++ Newbie 
Graphic Designer
===========================
-
Feb 4th, 2001, 04:27 PM
#8
Thread Starter
Hyperactive Member
how about this?
I red that if you save the h file in your current work space then you should use "" and I was wondering, if you add it into your include folder can you use by saying
#include <colorfunction.h> ?
===========================
Kourosh Gonabadi
VB Programmer 
C++ Newbie 
Graphic Designer
===========================
-
Feb 4th, 2001, 04:30 PM
#9
Monday Morning Lunatic
Yep. However, you should never add anything to your main includes folder. The best way is to set aside another folder, and add that to the list of includes folders. That way you can use <colorfunction.h> (RANT: can't anyone spell???) in your programs.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 4th, 2001, 04:36 PM
#10
Thread Starter
Hyperactive Member
Originally posted by parksie
Yep. However, you should never add anything to your main includes folder. The best way is to set aside another folder, and add that to the list of includes folders. That way you can use <colorfunction.h> (RANT: can't anyone spell???) in your programs.
Acording to what you said I should another folder to my include folder and add the user defined libraries in that. Right? So when I am using the #include <colorfunciton.h> should I also specify the path to the folder?
Let's say the folders name is udefined, shouldn't I use
#include<udefined\colorfunction.h>
or would the compiler automatically search all the include folder incloding the subfolders??
===========================
Kourosh Gonabadi
VB Programmer 
C++ Newbie 
Graphic Designer
===========================
-
Feb 4th, 2001, 04:40 PM
#11
PowerPoster
why is it bad to add files to the compilers include folder? I did, and everything seems, maybe i screwed something up i didn't even knowabout.
-
Feb 4th, 2001, 05:03 PM
#12
It's bad to add files to the compilers include directory, because you may replace something that is needed, and the directory should be used just for the compilers stuff...
what I do is make a directory, c:\include
and put all my extra files in there.. then on whatever compiler I have, I add an extra include path(paths are seperated by semicolons). then all you have to do is include it normally..
#include <colorfunctions.h> (The compiler looks in both directories for the file)
Mike:
It may seem wierd to you, but color is normal Americanese... if we were to spell colour on a report at school or something, it would be marked incorrect....
-
Feb 4th, 2001, 05:28 PM
#13
Monday Morning Lunatic
For the spelling...I feel really sorry for you guys 
Nah, it's okay -- I'm not totally bothered...I'm just a perfectionist so ignore me
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 4th, 2001, 05:57 PM
#14
Thread Starter
Hyperactive Member
Thanks
Thanks alot to everybody I think I got what I was looking for.
Parksie, don't worry about it. I didn't notice what you wrote about spelling and anyway I admit my spelling is sux. . Although it's really bad that my spelling is not good. Man I am wondering what was Bill thinking about! He should have integrated an spell check with the C++.
===========================
Kourosh Gonabadi
VB Programmer 
C++ Newbie 
Graphic Designer
===========================
-
Feb 4th, 2001, 05:59 PM
#15
Monday Morning Lunatic
Hehehe:
"Compiler Error C6660: Your variable name is incorrectly spelt"
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|