Jon Stewart on 6 Aug 2003 23:30:58 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] problem with const


> Well, the unfortunate thing is that it doesn't determine the const-ness 
> of Wrapper automatically.  You'd like
> 
> Wrapper<const Foo> w(myConstFooRef)
> 
> not to compile, I presume.  I'm not sure how to achieve this with 
> normal constructor semantics, though.


Actually, that's not a big deal (although, again, ugly). Any non-const 
member functions which try to access the member data will fail to compile. 
Of course, they won't be generated for the particular template 
specialization unless you try to use them.

One problem:

	const Wrapper<const Foo> cw;

	Wrapper<> w(cw);

is difficult.

template<class FooType = Foo>
class Wrapper {
public:
	Wrapper(const Wrapper<FooType> &w) : m_Foo(w.m_Foo) {}
	Wrapper(const Wrapper<const FooType> &cw) : m_Foo(cw.m_Foo) {}
};

This prefers not to compile.



Jon
-- 
Jon Stewart                                 Advanced Los Angeles C++
stew1@xxxxxxxxxxx                           http://www.alacpp.org
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp