我目前正在阅读Accelerated C ++ ch13,并考虑通过boost scoped_ptr进行书中给出的示例程序,但遇到了错误。
愿你们请我救我。
**
***error: cannot use arrow operator on a type
record->read( cin );***
^
**
原始示例代码如下所示,此功能完美无缺
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 );
}
现在使用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 );
}