I am currently reading Accelerated C++ ch13 and thought of doing sample program given in book via boost scoped_ptr but have encountered an error.
May you guys please bail me out.
**
***error: cannot use arrow operator on a type
record->read( cin );***
^
**
Original sample code is something shown below and this works flawlessly
std::vector< Core* > students ; // read students
Core* records;
std::string::size_type maxlen = 0;
// read data and store in an object
char ch ;
while( cin >> ch )
{
if( 'U' == ch )
{
records = new Core;
}
else if( 'G' == ch )
{
records = new Grad;
}
records->read( cin );
maxlen = max( maxlen , records->getname().size() );
students.push_back( records );
}
Now using scoped_ptr MY VERSION
typedef boost::scoped_ptr<Core> record;
std::vector< record > students;
char ch;
std::string::size_type maxlen = 0;
// read and store
while( ( cin >> ch ) )
{
if( ch == 'U')
{
record( new Core);
}
else if( ch == 'G')
{
record( new Grad);
}
record->read( cin );// GOT ERROR
//maxlen = max( maxlen, record->name().size() );// SAME type of error I EXPECT HERE
// students.push_back( record );
}