A
abhay.burli
Hello Group,
Consider the following class design using forward declarations.
//start-snip
#include<memory>
class Details;
class MyConcrete {
private:
std::auto_ptr<Details> details_;
};
int main() {
MyConcrete obj;
return 0;
}
// end-snip
comeau gives the following warning(s) :
// statrt-snip
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for
ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"memory", line 76: warning: delete of pointer to incomplete class
~auto_ptr() { delete _M_ptr; }
^
detected during:
instantiation of
"std::auto_ptr<_Tp>::~auto_ptr() [with
_Tp=Details]" at
line 11 of "ComeauTest.c"
implicit generation of "MyConcrete::MyConcrete()" at line
11 of
"ComeauTest.c"
In strict mode, with -tused, Compile succeeded
// end-snip
As we see, std::auto_ptr requires complete definition of the class to
be used as a smart-pointer unlike if we compose using only a class-
pointer(Details*).
I have a lot of such similar forward declarations (recommended
physical design). Using std::auto_ptr would have made writing
exception-safe operator= (...) easier on these classes so...
Q-1. Does the above warning lead to only memory leaks or something
more ?
Q-2. Do boost smart-pointers also have the same semantics w.r.t to the
above situation?
Q-3. Any suggestions on redesign? Something like using PIMPL, and
implement the above concrete class in a .cpp file where i can #include
the composed class definition though;it is quite a lot of redesign!
Thanks in advance,
Abhay
Consider the following class design using forward declarations.
//start-snip
#include<memory>
class Details;
class MyConcrete {
private:
std::auto_ptr<Details> details_;
};
int main() {
MyConcrete obj;
return 0;
}
// end-snip
comeau gives the following warning(s) :
// statrt-snip
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for
ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"memory", line 76: warning: delete of pointer to incomplete class
~auto_ptr() { delete _M_ptr; }
^
detected during:
instantiation of
"std::auto_ptr<_Tp>::~auto_ptr() [with
_Tp=Details]" at
line 11 of "ComeauTest.c"
implicit generation of "MyConcrete::MyConcrete()" at line
11 of
"ComeauTest.c"
In strict mode, with -tused, Compile succeeded
// end-snip
As we see, std::auto_ptr requires complete definition of the class to
be used as a smart-pointer unlike if we compose using only a class-
pointer(Details*).
I have a lot of such similar forward declarations (recommended
physical design). Using std::auto_ptr would have made writing
exception-safe operator= (...) easier on these classes so...
Q-1. Does the above warning lead to only memory leaks or something
more ?
Q-2. Do boost smart-pointers also have the same semantics w.r.t to the
above situation?
Q-3. Any suggestions on redesign? Something like using PIMPL, and
implement the above concrete class in a .cpp file where i can #include
the composed class definition though;it is quite a lot of redesign!
Thanks in advance,
Abhay