i have the following function and when i want to run the programe it give me error
here is the code for the function
[
virtual void printOn( ostream & os ) const
{
// Save the current flags and precision before modifying them.
unsigned svflags = os.setf( ios::showpoint | ios::fixed );
int svprecision = os.precision (2);
// Restore the previous flags and precision.
os.precision (svprecision );
os.flags ( svflags );
}
]
it give me the following error
155 invalid conversion from ` unsigned int' to `std::_Ios_Fmtflags'
155 invalid conversion from ` unsigned int' to `std::_Ios_Fmtflags'
when i compile the main program too it give me error.. i try to declare an object for classs TableAsArray, it give me error too... the code is below
[
int main()
{
// Open input file, get number of Packages,
// open output file, create table.
for (i = 0; i < numRecords; i++)
{
pkg = new PackageAll;
input >> *pkg;
ptable.AddItem ( pkg );
if( input.eof() ) break;
}
outfile << ptable << endl; //output the table
// Get each Package from the table, add its
// weight to a total, and display the total
// weight of all packages.
PackageAll * z;
float sum = 0.0;
for (i = 0; i < ptable.GetCount(); i++)
{
z = (PackageAll *)ptable.GetItemPtr ( i );
sum += z->GetWeight();
}
outfile << "Total weight of packages = " << sum << "\n\n";
if (n != UINT_MAX )
{
pkg = (PackageAll *)ptable.GetItemPtr( n );
outfile << "Package " << *pkg << "found at position " << n << '\n';
}
else
outfile << "Package not found. \n";
system("pause");
return 0;
}
]
it give me this error;
cannot declare variable `ptable' to be of type `TableAsArray'
because the following virtual functions are abstract:
virtual int Item::Compare(const Item&) const
virtual void Item::printOn(std::ostream&) const
virtual void Item::readFrom(std::istream&)
I will put the full program below to help you trace the error
The first is because the return type of setf is not unsigned int but std::_Ios_Fmtflags.
The others are because you probably have an abstract base class Item that has some pure virtual functions. TableAsArray is derived from that class and does not define those functions.
Post the code (the part where you declare/define your classes) if I'm wrong.
// Restore the previous flags and precision.
//os.precision ( svprecision );
//os.flags (svflags );
}
int Compare( const Item & I2) const
{
if (trackNum < ((PackageAll &)I2).trackNum )
return -1;
else if ( trackNum == ((PackageAll &)I2).trackNum )
return 0;
else // if ( trackNum > ((Package &)I2).trackNum )
return 1;
}
//compare this package I2,
//return -1 if *this is less than I2,
//return 0 if *this is equal to I2,
//return 1 if *this is greater than I2
//function that set data member values:
void SetTrackNum( long &trackNumP )
{
trackNum = trackNumP;
}
void SetOrigin( long &originP )
{
origin = originP;
}
void Init()
{
long SetTrackNum (0);
long SetOrigin (0);
long SetDestination (0);
long SetDate(0);
float SetCost ( 0.0f );
float SetWeight (0.0f );
}
long trackNum; //tracking number
long origin; //originating zip code
long destin; //destination zip code
long date; //date sent (yymmdd)
float cost; //shipping cost
float weight; //weight in kilograms
virtual void printOn( ostream & os ) const
{
// Save the current flags and precision before modifying them.
unsigned svflags = os.setf( ios::showpoint | ios::fixed );
int svprecision = os.precision (2);
// Restore the previous flags and precision.
//os.precision (svprecision );
//os.flags ( svflags );
}
virtual void readFrom( istream & is ) ;
};
class Table : public Item{
public:
virtual ~Table() {}
virtual void AddItem( Item * ) = 0;
//add new item to the table.
virtual void Clear () = 0;
//empty the table
virtual unsigned GetCount() const = 0;
//return the number of entries in the table.
virtual Item * GetItemPtr( unsigned i ) const = 0;
//retrieve pointer to item at position i.
virtual unsigned IndexOf( const Item * P) const = 0;
//search for a matching item in the table;
//if found, return its index position,
//otherwise return UINT_MAX.
virtual void Sort() = 0;
//sort the table in ascending order
};