I want have class with a pointer member variable. This pointer should point to an object which may be stack-allocated or heap allocated. However, this pointer should do not have any ownership. In other words, no delete should be called at all if the pointer go out of scope. I think that raw pointer could solve the problem... However, I am not sure if there is a better C++11 approach than raw pointers?
Example:
class foo{
public:
bar* pntr
};
int main(){
bar a;
foo b;
b.pntr=&a;
}
Aucun commentaire:
Enregistrer un commentaire