473,396 Members | 1,996 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,396 software developers and data experts.

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 1455
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**********@gmail.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******@netscape.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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 TestConstructors();
void TestingSetters();
int Write(jme::Person&);
int main(int argc, char *argv[])
{
//TestConstructors();
TestingSetters();

system("PAUSE");

return EXIT_SUCCESS;
}

int Write(jme::Person& obj){
try{
//file IO handler
----
}
void TestingSetters(){
//testing all the setters and getters for class Person
}
void TestConstructors(){
//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
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...
9
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...
4
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...
5
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...
8
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...
11
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...
9
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...
20
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...
1
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');...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.