[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Behaviour of const KSharedPtrs
From: Stefan Teleman <steleman () nyc ! rr ! com>
Date: 2004-11-13 0:54:46
Message-ID: 200411121954.46336.steleman () nyc ! rr ! com
[Download RAW message or body]
Should the following code compile ?
#include <iostream>
using namespace std;
template<class T>
class Foo
{
public:
Foo() : _t(0) { }
Foo (const Foo& rhs) : _t(rhs._t) { }
~Foo() { }
Foo& operator= (const Foo& rhs)
{
if (this != &rhs)
_t = rhs._t;
return *this;
}
void set (T* t) { _t = t; }
T* get() const { return _t; }
private:
T* _t;
};
int
main (int argc, char* argv[])
{
Foo<int> foo;
int x = 7;
int y = 9;
foo.set(&x);
std::cerr << "foo = " << *(foo.get()) << endl;
foo.get() = &y;
std::cerr << "foo = " << *(foo.get()) << endl;
return 0;
}
--Stefan
-------------------------
On Friday 12 November 2004 19:48, Richard Smith wrote:
> Not for a smart pointer, it's not. The thing const-correctness
> covers for a pointer (or by extension a smart pointer) is not
> allowing changes to the value of the pointer (ie, disallowing
> assignment). You're getting const-correctness of the pointer
> confused with const-correctness of the pointee.
--
Stefan Teleman 'Nobody Expects the Spanish Inquisition'
steleman@nyc.rr.com -Monty Python
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic