Conversion operator

 


//operator() 

//conversion operator

#include<iostream.h>



class dist{

private:

int f;

int i;

float mtf;

public:

dist():f(0),i(0),mtf(3.28)

{}

dist(int ft,int in):f(ft),i(in),mtf(3.28)

{}

void get()

{

cout<<"Enter ft:";

cin>>f;

cout<<"Enter in";

cin>>i;

}

void show()

{

cout<<f<<" ' "<<i<<" ``"<<endl;

}

operator float() const

{

float fraf=i/12;

fraf+=static_cast<float>(f); return (fraf/mtf);

}

};

int main(int argc, char *argv[])

{

dist d1(3,12);

d1.show();

cout<<static_cast<float>(d1);

}

Comments

Popular posts from this blog

serial to parallel test with 74c595 and pic mcu

ဆိုလာ စနစ္ရွိ BATTERY AMPACITY အား design ထုတ္တြက္ခ်က္ၿခင္း (1) watt hour ရယူၿခင္း

INTERRUPT_ON_CHANGE_18f4550