[Development] QList

Thiago Macieira thiago.macieira at intel.com
Sun Mar 19 19:44:44 CET 2017


On sábado, 18 de março de 2017 14:33:32 PDT Marc Mutz wrote:
> On Saturday 18 March 2017 19:30:35 Thiago Macieira wrote:
> > class QStringView               - has all the const functions
> > class QString : public QStringView      - adds the mutating functions
> > class QtExclusive::QString : public QString
> 
> No inheritance. These things have no is-a relationship whatsoever.

Right, I came to the same conclusion in the shower after posting this and then 
forgot to post once I was out.

> Example: QString cannot inherit QStringView because QStringView::trimmed()
> returns a QStringView while QString::trimmed() needs to return a QString.

I don't see why you need to. If you called the object as QStringView, then you 
get QStringView too.

My problem was the exclusive kind, because you could then do:

	QtExclusive::QString es;
	QString &s = es;
	s = somethingElse();
	// es could now be sharing, which is a violation

> These return values aren't covariant, either, because a) they're not
> pointers, so C++ doesn't let you, b) the functions aren't virtual so C++
> won't let you and c) the QStringView implementation has no idea how to
> manage QString's memory.

Covariants are only needed if they were virtual. They're not, they can be just 
pure overrides.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list