'class' type redefinition

S

squallions

Hi

I doing my c++ homework and stuck on error 'class' type redefinition.

I have 5 classes. First class is base class. The next two classes are
derived from the first class. The next two classes are derived from
previous two classes. On the main file, I have...

#include "hw6a.h"
#include "hw6b.h"
#include "hw6c.h"
#include "hw6d.h"
#include "hw6e.h"

I got error "'class' type redefinition". If I commented all except the
last one, then class in those class file doesnt recognize when I
initialize an object.

Here is the file.

Main file:
http://users3.ev1.net/~sonle/school/cpp/hw6.cpp

Base class:
http://users3.ev1.net/~sonle/school/cpp/hw6a.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6a.h

Other derived class:
http://users3.ev1.net/~sonle/school/cpp/hw6a.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6a.h
http://users3.ev1.net/~sonle/school/cpp/hw6b.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6b.h
http://users3.ev1.net/~sonle/school/cpp/hw6c.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6c.h
http://users3.ev1.net/~sonle/school/cpp/hw6d.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6d.h
http://users3.ev1.net/~sonle/school/cpp/hw6e.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6e.h
Can someone sheds some light.
Thank.
Son
 
M

Mike Wahler

Hi

I doing my c++ homework and stuck on error 'class' type redefinition.

I have 5 classes. First class is base class. The next two classes are
derived from the first class. The next two classes are derived from
previous two classes. On the main file, I have...

#include "hw6a.h"
#include "hw6b.h"
#include "hw6c.h"
#include "hw6d.h"
#include "hw6e.h"

I got error "'class' type redefinition". If I commented all except the
last one, then class in those class file doesnt recognize when I
initialize an object.

Here is the file.

Main file:
http://users3.ev1.net/~sonle/school/cpp/hw6.cpp

Base class:
http://users3.ev1.net/~sonle/school/cpp/hw6a.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6a.h

Other derived class:
http://users3.ev1.net/~sonle/school/cpp/hw6a.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6a.h
http://users3.ev1.net/~sonle/school/cpp/hw6b.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6b.h
http://users3.ev1.net/~sonle/school/cpp/hw6c.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6c.h
http://users3.ev1.net/~sonle/school/cpp/hw6d.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6d.h
http://users3.ev1.net/~sonle/school/cpp/hw6e.cpp
http://users3.ev1.net/~sonle/school/cpp/hw6e.h
Can someone sheds some light.


Look up "include guards".


// hw6a.h

#ifndef HW6A_H
#define HW6A_H

class Conversion
{
// friend ostream and istream
friend ostream &operator << (ostream&, Conversion &);
friend istream &operator >> (istream&, Conversion &);

private:
double data, result;

public:
Conversion(double d = 0);
~Conversion();

double getData(void);

void setResult(double d);
double getResult(void);

virtual void convert() = 0;
virtual void display() = 0;
};

#endif


Do this for all your header files.

-Mike

P.S. You also posted this to alt.comp.lang.learn.c-c++.
That's OK, your question is topical in both newsgroups,
but if you want to post to more than one group, do
a crosspost, don't post two separate messages.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top