//cpeer.h

#ifndef CPEER_H_
#define CPEER_H_

#include <string>
struct CPeer
{
    std::string name;
};
#endif /*CPEER_H_*/

//cpeermanager.h

#ifndef CPEERMANAGER_H_
#define CPEERMANAGER_H_

class CPeer;

#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>


class CPeerManager
{
public:
  CPeerManager();
  boost::scoped_ptr<CPeer> cp_; //error
 // boost::shared_ptr<CPeer> cp_;  // ok
};

#endif /*CPEERMANAGER_H_*/

//cpeermanager.cpp

#include "cpeer.h"
#include "cpeermanager.h"



CPeerManager::CPeerManager():
cp_  (new CPeer() )
{
   
}

//main.cpp

#include "cpeermanager.h"

int main()
{
    CPeerManager cp;
}

i get

**** Build of configuration Debug for project scoped_ptr_test ****

make -k all
'Building file: ../cpeermanager.cpp'
'Invoking: GCC C++ Compiler'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"cpeermanager.d" -MT"cpeermanager.d" -o"cpeermanager.o" "../cpeermanager.cpp"
'Finished building: ../cpeermanager.cpp'
' '
'Building file: ../main.cpp'
'Invoking: GCC C++ Compiler'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp: In function 'void boost::checked_delete(T*) [with T = CPeer]':
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/scoped_ptr.hpp:77:   instantiated from 'boost::scoped_ptr<T>::~scoped_ptr() [with T = CPeer]'
../cpeermanager.h:11:   instantiated from here
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:32: error: invalid application of 'sizeof' to incomplete type 'CPeer'
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:32: error: creating array with negative size ('-0x000000001')
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:33: error: invalid application of 'sizeof' to incomplete type 'CPeer'
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:33: error: creating array with negative size ('-0x000000001')
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:34: warning: possible problem detected in invocation of delete operator:
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:29: warning: 'x' has incomplete type
../cpeermanager.h:4: warning: forward declaration of 'struct CPeer'
c:/mingw/bin/../lib/gcc/i686-pc-mingw32/4.1.2/../../../../include/boost/checked_delete.hpp:34: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project scoped_ptr_test

/// why boost::shared_ptr can used to Minimize compilation dependencies between files,
yet boost::scoped_ptr cannot.   I needn't to use reference cout.may someboby help me out of the trouble.thanks!
 


 



iPod、万 点 巨 额 点 卡、奖 学 金……海 量 奖 品,想 拿 就 拿!