M
mati-006
Hi,
I think the code will be the best way to explain what I mean:
#include "arglib/arg_shared.h"
class base {
public:
base() {}
virtual ~base() {}
};
class derived : public base {
public:
derived() {}
~derived() {}
};
int main()
{
arg::counted_ptr<base> bsp;
arg::counted_ptr<derived> dsp(new derived);
base * bp;
derived * dp(new derived);
bp=dp;
bsp=dsp;
}
The smart pointers I'm using are documented here:
http://www.octopull.demon.co.uk/arglib/class_arg__counted_ptr.html
The problem:
bp=dp; - works
bsp=dsp; - doesn't work, compile error:
test.cpp: In function `int main()':
test.cpp:16: error: no match for 'operator=' in 'bsp = dsp'
arglib/arg_shared.h:312: error: candidates are:
arg::counted_ptr<pointee_type>&
arg::counted_ptr<pointee_type>:perator=(const
arg::typed_reference<pointee_type>&) [with pointee_type = base]
arglib/arg_shared.h:324: error:
arg::counted_ptr<pointee_type>&
arg::counted_ptr<pointee_type>:perator=(const
arg::counted_ptr<pointee_type>&) [with pointee_type = base]
make: *** [test.o] Error 1
Question is, what is the best way to deal with upcasting using smart
pointers? Or maybe I'm using not-so-smart pointers and the upcasting
thing is possible with properly written smart pointers?
I think the code will be the best way to explain what I mean:
#include "arglib/arg_shared.h"
class base {
public:
base() {}
virtual ~base() {}
};
class derived : public base {
public:
derived() {}
~derived() {}
};
int main()
{
arg::counted_ptr<base> bsp;
arg::counted_ptr<derived> dsp(new derived);
base * bp;
derived * dp(new derived);
bp=dp;
bsp=dsp;
}
The smart pointers I'm using are documented here:
http://www.octopull.demon.co.uk/arglib/class_arg__counted_ptr.html
The problem:
bp=dp; - works
bsp=dsp; - doesn't work, compile error:
test.cpp: In function `int main()':
test.cpp:16: error: no match for 'operator=' in 'bsp = dsp'
arglib/arg_shared.h:312: error: candidates are:
arg::counted_ptr<pointee_type>&
arg::counted_ptr<pointee_type>:perator=(const
arg::typed_reference<pointee_type>&) [with pointee_type = base]
arglib/arg_shared.h:324: error:
arg::counted_ptr<pointee_type>&
arg::counted_ptr<pointee_type>:perator=(const
arg::counted_ptr<pointee_type>&) [with pointee_type = base]
make: *** [test.o] Error 1
Question is, what is the best way to deal with upcasting using smart
pointers? Or maybe I'm using not-so-smart pointers and the upcasting
thing is possible with properly written smart pointers?