O
Oleksii
Hello,
I'm rather new to the advanced topics, therefore I cannot explain the
following myself. Could anyone give me a hint on this one?
I'm trying to avoid link-time dependencies on (a test version of)
certain classes. In other words I don't want to link stuff that I don't
use. One thing that worked for me was replacing instance members
(MyClass myClass) within a class with auto_ptr (auto_ptr<MyClass>
myClass) and initializing it with a new instance of a class in the
product code and a NULL in the test code.
This works... unless the class being auto_ptr'ed has a non-virtual
destructor. The linker is happily eating input with virtual
destructors. Otherwise the implementation of the destructor is claimed
to be missing.
The whole thing was originally tested on M$ visual studio compiler,
then on gcc (cygwin/3.4.4).
Is this a feature of compiler(s) being too smart (even when all
optimizations are disabled) or is it an expected behavior? What exactly
is happening here? If this is compiler-specific I assume it is not very
scalable and I'd better drop using it. Any other suggestions in that
case?
Here is some sample code:
#include <memory>
#include <iostream>
class MyClass2
{
public:
MyClass2() {};
virtual ~MyClass2();
};
int main()
{
// Uncommenting the following line would lead to complaint
// from linker that requires implementation for ~MyClass2().
// std::auto_ptr<MyClass2> myClass2r (new MyClass2);
std::auto_ptr<MyClass2> myClass2n;
}
p.s. I'm working on a rather big legacy code thing and therefore a bit
limited in redesign. Link-time stubbing for test purposes seems to be
the easiest approach.
Thanks in advance, Oleksii.
I'm rather new to the advanced topics, therefore I cannot explain the
following myself. Could anyone give me a hint on this one?
I'm trying to avoid link-time dependencies on (a test version of)
certain classes. In other words I don't want to link stuff that I don't
use. One thing that worked for me was replacing instance members
(MyClass myClass) within a class with auto_ptr (auto_ptr<MyClass>
myClass) and initializing it with a new instance of a class in the
product code and a NULL in the test code.
This works... unless the class being auto_ptr'ed has a non-virtual
destructor. The linker is happily eating input with virtual
destructors. Otherwise the implementation of the destructor is claimed
to be missing.
The whole thing was originally tested on M$ visual studio compiler,
then on gcc (cygwin/3.4.4).
Is this a feature of compiler(s) being too smart (even when all
optimizations are disabled) or is it an expected behavior? What exactly
is happening here? If this is compiler-specific I assume it is not very
scalable and I'd better drop using it. Any other suggestions in that
case?
Here is some sample code:
#include <memory>
#include <iostream>
class MyClass2
{
public:
MyClass2() {};
virtual ~MyClass2();
};
int main()
{
// Uncommenting the following line would lead to complaint
// from linker that requires implementation for ~MyClass2().
// std::auto_ptr<MyClass2> myClass2r (new MyClass2);
std::auto_ptr<MyClass2> myClass2n;
}
p.s. I'm working on a rather big legacy code thing and therefore a bit
limited in redesign. Link-time stubbing for test purposes seems to be
the easiest approach.
Thanks in advance, Oleksii.