473,797 Members | 3,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bugs in my code, help!!

This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

Any help towards the solution of my problem will be most appreciated.

TIA.

Feb 4 '06 #1
9 1478
Jamiil wrote:
This is not a question where the source code is important, it is not
important at all.
yet it is the source code that has a bug in it...

So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?


could you post the *exact* text of the error message(s)?
--
Nick Keighley

Feb 4 '06 #2
TB
Jamiil sade:
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

In your subject you state that there are bugs in your code, and
yet you proclaim the code to be of no significant value when trying
to find them.
Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Not really, see <fstream>.
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?


Well, it said you're including more than one definition of 'Person'. Why
would you have to "go line by line" scavenging like a nfa? Isn't gcc
telling you where? What is gcc actually telling you?

--
TB @ SWEDEN
Feb 4 '06 #3

Jamiil wrote:
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code.... Any help towards the solution of my problem will be most appreciated.


The answer is obvious: 42.

Feb 4 '06 #4
TB wrote:
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'.


Well, it said you're including more than one definition of 'Person'. Why
would you have to "go line by line" scavenging like a nfa? Isn't gcc
telling you where? What is gcc actually telling you?


gcc just shows you where the duplicate definition is,
but it does not tell you to use header guards :-)

Stephan

Feb 4 '06 #5
On 4 Feb 2006 09:28:29 -0800, ro**********@gm ail.com wrote:
Any help towards the solution of my problem will be most appreciated.


The answer is obvious: 42.


I thought it was 42 / (towel * bathtub) reflected in a mirror. Hmm...
I guess I was doing a "Rube Goldberg" there.

In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
- Douglas Adams
Feb 4 '06 #6
Jamiil
I guess the problem is with header file inclusion. are you including
the Person header in the io_base cpp and io_base header in the Person
cpp ? and does the person header has header guard? check these first.
please post the full gcc error

hope it helps

Feb 5 '06 #7

"Jamiil" <ja******@netsc ape.net> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

Any help towards the solution of my problem will be most appreciated.

TIA.


Most likely is it because your include file for person does not have include
guards. That is, guards that prevent the same header from being included
twice. Simple at this:

person.h file:

#ifndef PERSON_H
#define PERSON_H

// header junk here

#endif

Now, if you have files that include files, and person.h gets included twice
in the same compilation unit, it won't cause an error because of the include
guards.

If this isn't the answer, the answer is obvious: 42.
Feb 5 '06 #8

Jim Langston wrote in message ...

If this isn't the answer, the answer is obvious: 42.


Before 42ing, try 'inline'!

--
Bob R
POVrookie
Feb 6 '06 #9
Thanks for the prompt response.
Yes, that is the proble, but since each declaration file has 'inclusion
guards' I did not expect it to be a problem. What can I do to solve
this problem?
Again thanks so much!

Here is a posting with a little more info.

--- main.c ---
#include <cstdlib>
#include <iostream>
#include <string>
#include <limits.h>
#include <complex.h>

#include "../strtools/strtools.hpp"
#include "../gnu_io/gnu_io.hpp"
#include "person.hpp "

using namespace std;
void TestConstructor s();
void TestingSetters( );
int Write(jme::Pers on&);
int main(int argc, char *argv[])
{
//TestConstructor s();
TestingSetters( );

system("PAUSE") ;

return EXIT_SUCCESS;
}

int Write(jme::Pers on& obj){
try{
//file IO handler
----
}
void TestingSetters( ){
//testing all the setters and getters for class Person
}
void TestConstructor s(){
//Testing all the contructors for class Person
}

--- Person.hpp ----
#ifndef JME_PERSON_HPP
#define JEM_PERSON_HPP

#include <cstring>
#include <string>

#include "../exception/exception.hpp"
#include "../strtools/strtools.hpp"
#include "../name/name.hpp"
#include "../address/address.hpp"
#include "../email/email.hpp"
#include "../phone/phone.hpp"
#include "../url/url.hpp"
#include "../io_base/io_base.hpp" //<<<==== ??
#include "../gnu_io/gnu_io.hpp"
#include "../index/index.hpp"

#include <deque>
#include <algorithm>
#include <fstream>
namespace jme{

class Person{
// A whole bunch of variables and functions go here
};
}

--- person.cpp ---
#ifndef JME_PERSON_HPP
#include "person.hpp "
#endif
// A whole bunch of variable are assigned values through
// the uses of setters and getters.
--- io_base.hpp --
#ifndef JME_IO_BASE_H
#define JME_IO_BASE_H

#include <fstream>
#include <string>
#include "../exception/exception.hpp"
#include "../strtools/strtools.hpp"
#include "../name/name.hpp"
#include "../date/date.hpp"
#include "../money/money.hpp"
#include "../address/address.hpp"
#include "../email/email.hpp"
#include "../phone/phone.hpp"
#include "../url/url.hpp"
#include "../index/index.hpp"
#include "../person/person.hpp" //<<<<==== ??

Like most projects, this class belongs to a group library. When
testing the class as an isulated class, the program compiles without
any problems, however, when adding rest to the library to the test
program, the compiler complains sying that class Person has been
previously declared. I know, for a fact, that there is no redeclaration
of class Person. What I believe is happening is that I forgot to close
a bracket in a try block or anywhere else, but the compiler detects the
problem as being a redefined of the class Person.
This is the exact error code message:
Compiler: Default compiler
Building Makefile: "C:\Jamiil\dev\ c++\jme\person\ Makefile.win"
Executing make...
make.exe -f "C:\Jamiil\dev\ c++\jme\person\ Makefile.win" all
g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/GnuWin32/INCLUDE"
-I"C:/GnuWin32/INCLUDE/GTK-2.0" -I"C:/GnuWin32/INCLUDE/GLIB-2.0"
-I"C:/GnuWin32/INCLUDE/PANGO-1.0" -I"C:/GnuWin32/INCLUDE/CAIRO"
-I"C:/GnuWin32/INCLUDE/ATK-1.0" -I"C:/GnuWin32/INCLUDE/GTKGLEXT-1.0"
-I"C:/GnuWin32/LIB/GTK-2.0/INCLUDE"
-I"C:/GnuWin32/LIB/GLIB-2.0/INCLUDE"
-I"C:/GnuWin32/LIB/GTKGLEXT-1.0/INCLUDE"
-I"C:/GnuWin32/INCLUDE/LIBGLADE-2.0" -I"C:/GnuWin32/INCLUDE/LIBXML2"
-fexceptions -fverbose-asm -pg -g3

In file included from main.cpp:9:
person.hpp:26: error: redefinition of `class jme::Person'
.../gnu_io/..\io_base\/../person/person.hpp:26: error: previous
definition of `class jme::Person'

make.exe: *** [main.o] Error 1

Execution terminated
Thanks!!

iftekhar wrote:
Jamiil
I guess the problem is with header file inclusion. are you including
the Person header in the io_base cpp and io_base header in the Person
cpp ? and does the person header has header guard? check these first.
please post the full gcc error

hope it helps


Feb 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1046
by: JasonD | last post by:
I'm a college student working on a little program, and I've run into two problems. I am using C++ (console app). 1) When I enter debugging mode, with the program breaking somewhere, the "Watch 1" and "Locals" debug windows are tabbed at the buttom, but they will not open. The other debug windows open fine, though. I cannot remove the tabs. Clicking a tab only brings it to the front of the tab control. I do not know what I did to...
9
2415
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
4
2830
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual Basic code that will examine numeric value for a particular field in a query, and assign a new numeric vaule to that field. There are over 21 possible values and I am told that IIF statement will only handle 9 of the possibilities and that I need...
5
1302
by: deercreek | last post by:
I could use a little help from a good code writer out there. I found some code and modified it a bit for my needs but, I need a little help to finish it up. What I am trying to due is to get a number to fill out a text box on my form. I want it to look at the form and get the CampStartDate and my CampEndDate also to look at a table of holidays. Then I want the text box to be filled with the number of days they will be staying that do not...
8
1787
by: goldtech | last post by:
Newbie esp about html validation - seems like something to strive for. Yet many pages even "enterprise" corporate type pages do not validate, yet seem to display well on most browsers. Two questions: 1. What is the reward, the reason to strive for a validating page? 2. Given the code snippet below which does not validate - how can accomplish the same "look" with code that does validate? Please without CSS, just html. Thanks ....
11
2112
by: ThaRealneSS | last post by:
Hi. I have made a blackjack code and need a some help on it. It seems to work overall but there are a few bits here and there that need sorting out, and I'm kinda stuck on it so was wondering if I could get some help? (Would be HUGELY appreciated ) The things I need help are on: - Stopping the program going back to the code (you will know what I mean when you play it) - How to add the re-run code in it and where - How I can count...
9
7357
by: Chris Ahmsi | last post by:
I have been tasked to create a 'simple' form in Access providing managers to input necessary changes. I have 2 command buttons on the form and a check box. Command button 1 updates my table for multiple entries, and command button 2 e-mails the table in HTML format to my team, appends the data entered to a back-up table, and deletes the entries on the current table. When the check box on my form is checked (indicating a permanent change) I...
20
1948
by: 16800960 | last post by:
The Code is as Follows bool findTitlePrice(string allTitles, double allPrices, int totalRec, string title, double & price) { for(int i=0; i < totalRec; i++) { // your code here: // for each element of array allTitles, check if it matches // the given title, i.e. if title and allTitles are the same;
1
2973
by: Joshua T | last post by:
I am not very good with MySQL server side scripts. So any help would be awesome! My database info is as follows: <?php define('DB_HOST', 'pingback.db.5645640.hostedresource.com'); define('DB_USER', 'pingback'); define('DB_PASSWORD', 'Wind**p1'); define('DB_DATABASE', 'pingback'); ?> This is how my sql is setup:
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10246
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.