Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-18-2005, 07:37 AM   #1 (permalink)
Lordieth
Registered User
 
Join Date: Sep 2005
Posts: 12
Lordieth is on a distinguished road
Multiple Files

Hey all.

I'm currently writing a program in C++ using Dev-C++ 4.9.9.2, and running into a few problems. My code has gotten rather large, and I decided to seperate some of my functions into a seperate sourcefile, and keep the function prototypes in a header file, following the tutorial to the letter - now when I try to compile it, I get a mess of errors, and i'm not sure what i'm doing wrong - even the tutorial does the same thing now!

The functions source file:

Code:
#include"OurHeader.h"
The header file:
Code:
#ifndef OURHEADER_H
#define OURHEADER_H

void Function1();
void Function2();

#endif
Main file:

Code:
#include"OurHeader.h"
Now as far as I can tell that's all correct - or is it? I'm in a bit of a mess really, if anyone can point to a correct way of doing multiple files in Devc++, or perhaps point me in the way of a working tutorial, i'd be very grateful - thankyou. I thought the problem might be because I wasn't using a project - so I attempted putting all the files into the project, and got the same errors, the errors are as follows:

1 [Warning] `nul.gcda' is not a gcov data file

Then a rather lengthy list of things apparantly not being declared, as if I hadn't included the right includes, which I have
Lordieth is offline   Reply With Quote
Old 09-18-2005, 09:48 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
1) Start up your IDE.
2) Create a new project.
2b) A main cpp file is automatically created.
3) Go to: File->New->Source File.
3b) Select "OK" when dialog box asks if you would like to add this file to the current project.
4) Go to step 3 and 3b again.
5) Save them as "OurFile.hpp" and "OurFile.cpp".
6) Declare the functions in your header the way you did.
7) Define the functions in your source file and include the header obviously.
8) Include the header in main source file as well and then just use the functions.

main.cpp
Code:
#include "OurFile.hpp"
#include <iostream>

int main()
{
  Function1();
  Function2();
  return 0;
}
OurFile.hpp
Code:
#ifndef OURHEADER_H
#define OURHEADER_H

void Function1();
void Function2();

#endif //OURHEADER_H
OurFile.cpp
Code:
#include "OurFile.hpp"
#include <iostream>

void Function1()
{
  std::cout<<"Function 1"<<std::endl;
}

void Function2()
{
  std::cout<<"Function 2"<<std::endl;
}
__________________
Valmont is offline   Reply With Quote
Old 09-18-2005, 12:37 PM   #3 (permalink)
Lordieth
Registered User
 
Join Date: Sep 2005
Posts: 12
Lordieth is on a distinguished road
Hey, thanks for that

It compiled and ran correctly, but still got this compiler error message:
Code:
1 [Warning] `nul.gcda' is not a gcov data file
Strange.....
Lordieth is offline   Reply With Quote
Old 09-18-2005, 12:43 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
In that case, I'd go to the Dev-Cpp forum and ask dev cpp specific questions there. I personally never encountered this problem so I don't know.
__________________
Valmont is offline   Reply With Quote
Old 09-18-2005, 01:10 PM   #5 (permalink)
Lordieth
Registered User
 
Join Date: Sep 2005
Posts: 12
Lordieth is on a distinguished road
Well, i've used this method to sort out my multiple file problem, and it seemed the problem wasn't my files or using the .h file and whatnot - it was that:

A) one function prototype was missing a ";"
B) I forgot to declare namespace std; in my functions source file




But i'll be using this new method from now on, as it looks a lot neater. The error just seems to be another silly thing Dev throws out - it can be pretty silly like that - cheers again.
Lordieth is offline   Reply With Quote
Old 09-18-2005, 01:26 PM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Ah, glad you figured it out. Here is a little tip: don't add "using namespace std;" in files. Every file that depends on it is forced to use the same namepspace. This defeats the purpose of namespaces. Since you are looking for a new style, I'd reccomend to always type std:: explicitly like I did. It's more typing but at least it is correct. Good luck!
__________________
Valmont is offline   Reply With Quote
Old 09-19-2005, 07:13 AM   #7 (permalink)
Lordieth
Registered User
 
Join Date: Sep 2005
Posts: 12
Lordieth is on a distinguished road
Thanks again - advice taken on board
Lordieth is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating .swf files at random with JavaScript? VisionsIC HTML, XML, Javascript, AJAX 0 05-18-2005 11:12 AM
Temp Internet Files - Delete wendyng HTML, XML, Javascript, AJAX 0 04-18-2005 10:30 PM
.h files needed Maani Standard C, C++ 7 02-02-2005 04:59 AM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM
All Class Files mixingsoup PHP 12 12-04-2002 06:49 AM


All times are GMT -8. The time now is 05:10 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting