I am doing a program to convert feet to meter and vice verse. I using classes and type conversions. both conversion functions( using constructor) use members of other class.So i used forward declaration of class FEET
#include<iostream>
#include<conio.h>
using namespace std;
class FEET;
class MEETER
{
int mtr;
double cm;
public:
MEETER()
{
mtr=0;
cm=0;
}
void getdata();
void display();
int get_mtr()
{
return(mtr);
}
double get_cm()
{
return(cm);
}
MEETER(FEET f)
{
int feet=f.get_feet();
double inch=f.get_inch();
inch+=feet*12;
cm=inch*2.54;
mtr=int(cm)/100;
cm=cm-(mtr*100);
}
~MEETER()
{
}
};
class FEET
{
int ft;
double in;
public:
FEET()
{
ft=0;
in=0;
}
void getdata();
void display();
int get_feet()
{
return(ft);
}
double get_inch()
{
return(in);
}
FEET(MEETER f)
{
int mtr=f.get_mtr();
double cm=f.get_cm();
cm+=mtr*100;
in=cm/2.54;
ft=int(in)/12;
cm=cm-(ft*12);
}
~FEET()
{
}
};
void MEETER::getdata()
{
cout<<"\nEnter length in meter and centimeter\n";
cin>>mtr>>cm;
}
void MEETER::display()
{
cout<<"\n"<<mtr<<"m "<<cm<<"cm\n";
}
void FEET::getdata()
{
cout<<"\nEnter length in feet and inch\n";
cin>>ft>>in;
}
void FEET::display()
{
cout<<"\n"<<ft<<"\""<<in<<"\n";
}
int main()
{
FEET f1,f2;
MEETER m1,m2;
f1.getdata();
m1=f1;
m2.getdata();
f2=m2;
f1.display();
m1.display();
f2.display();
m2.display();
getch();
return(0);
}
But program shows error as follows:
1>------ Build started: Project: Type_Length, Configuration: Debug Win32 ------
1> source.cpp
1>g:\abhi\type_length\type_length\source.cpp(27): error C2027: use of undefined type 'FEET'
1> g:\abhi\type_length\type_length\source.cpp(4) : see declaration of 'FEET'
1>g:\abhi\type_length\type_length\source.cpp(27): error C2228: left of '.get_feet' must have class/struct/union
1>g:\abhi\type_length\type_length\source.cpp(28): error C2027: use of undefined type 'FEET'
1> g:\abhi\type_length\type_length\source.cpp(4) : see declaration of 'FEET'
1>g:\abhi\type_length\type_length\source.cpp(28): error C2228: left of '.get_inch' must have class/struct/union
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Help me to fix it