Hello,
I've code like :
=============== =============== =============
class A{
public :
// create print content
friend std::ostream& operator<< (std::ostream&
os, const A& a);
}
typedef boost::shared_p tr<AAPtr; // Define A class smart pointer
APtr aPtr1(new A());
APtr aPtr2(new A());
APtr aPtr3(new A());
vector<APtrAVec ;
AVec.push_back( aPtr1);
AVec.push_back( aPtr2);
AVec.push_back( aPtr3);
std::copy(AVec. begin(),AVec.en d(),
std::ostream_it erator<APtr>(st d::cout, "\n"));
std::copy(AVec. begin(),AVec.en d(), std::ostream_it erator< share_ptr<A>
=============== =============== =============
The two copy methods only output the address of pointers, they could
just print the class A defined print contents. And following code
works :
=============== =============== =============
vector<APtr>::i terator i = AVec.begin();
for(; i!= AVec.end(); ++i){
cout << *static_cast<AP tr>(*i) << endl;
}
=============== =============== =============
Anyone has some ideas for that ? Thank you in advance.
Jun
I've code like :
=============== =============== =============
class A{
public :
// create print content
friend std::ostream& operator<< (std::ostream&
os, const A& a);
}
typedef boost::shared_p tr<AAPtr; // Define A class smart pointer
APtr aPtr1(new A());
APtr aPtr2(new A());
APtr aPtr3(new A());
vector<APtrAVec ;
AVec.push_back( aPtr1);
AVec.push_back( aPtr2);
AVec.push_back( aPtr3);
std::copy(AVec. begin(),AVec.en d(),
std::ostream_it erator<APtr>(st d::cout, "\n"));
std::copy(AVec. begin(),AVec.en d(), std::ostream_it erator< share_ptr<A>
>(std::cout, "\n"));
The two copy methods only output the address of pointers, they could
just print the class A defined print contents. And following code
works :
=============== =============== =============
vector<APtr>::i terator i = AVec.begin();
for(; i!= AVec.end(); ++i){
cout << *static_cast<AP tr>(*i) << endl;
}
=============== =============== =============
Anyone has some ideas for that ? Thank you in advance.
Jun
Comment