LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2003, 02:19 PM   #1
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Rep: Reputation: 15
C++ question


My c++ (what a joke) and now Im getting this retarded error I can't figure out.

any help would be appreciated. Ive tried everything including renaming the class and using namespace std and all that.

here are the file, it says Ive redeclared the class animal.

::UhUnix2:: gcc -c main.cpp
In file included from /usr/local/lib/gcc-lib/../../include/c++/3.3/backward/iostream.h:31,
/usr/local/lib/gcc-lib/../../include/c++/3.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
In file included from bird.h:2,
from main.cpp:3:
animal.h:2: error: redefinition of `class animal'
animal.h:2: error: previous definition of `class animal'
In file included from cow.h:1,
from main.cpp:4:
animal.h:2: error: redefinition of `class animal'
animal.h:2: error: previous definition of `class animal'
In file included from main.cpp:4:
cow.h:12:3: warning: no newline at end of file
main.cpp:27:2: warning: no newline at end of file
animal.h:8: warning: inline function `animal::~animal()' used but never defined
animal.h:8: warning: inline function `animal::~animal()' used but never defined
animal.h:7: warning: inline function `animal::animal()' used but never defined
animal.h:8: warning: inline function `animal::~animal()' used but never defined

http://www2.hawaii.edu/~benderj/cow.cpp
http://www2.hawaii.edu/~benderj/bird.cpp
http://www2.hawaii.edu/~benderj/animal.cpp
http://www2.hawaii.edu/~benderj/animal.h
http://www2.hawaii.edu/~benderj/bird.h
http://www2.hawaii.edu/~benderj/cow.h
http://www2.hawaii.edu/~benderj/main.cpp
 
Old 11-19-2003, 02:36 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well yes you ARE redefining variables, as you have two includes for the sames header. you need to use preprocessor checks:

Code:
#ifndef ANIMAL_H
include "animal.h"
#endif

#define ANIMAL_H
this ensures the header there is only included once. obviously once it is included it is available to the entire code...
 
Old 11-19-2003, 02:36 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Use g++ to compile the program. It should be better.
First note looking into the source code: when writing something.h file, do it the following way
Code:
#ifndef SOMETHING_H
#define SOMETHING_H

//your definitions here

#endif
The variable (SOMETHING_H) must be different in all files. Such a construction allows to load one header once only In your code, one header may be loaded multiple times, what causes a problem.
Not sure if it's all, but it should help.
 
Old 11-19-2003, 03:02 PM   #4
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
im a moron, seriously
 
Old 11-19-2003, 03:44 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally posted by ooagentbender
im a moron, seriously
i'd like to say i know the feeling but....

oh...

yes i DO know the feeling.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 03:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration