scoped_ptr调用成员函数抛出错误

时间:2015-04-05 02:21:09

标签: c++ boost scoped-ptr

我目前正在阅读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 );

    }

0 个答案:

没有答案