Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: "delete"

27 views
Skip to first unread message

Victor Bazarov

unread,
Mar 14, 2016, 10:38:34 AM3/14/16
to
On 3/14/2016 9:37 AM, Stefan Ram wrote:
> I read a part of the specification of C++. It suggests than
> one can use »delete« outside of a class! I never saw this
> before, but I made this up:
>
> void f( double ){}
> void f( int )= delete;
>
> int main()
> { f( 2.3 );
> /* f( 2 ); */ }
>

Don't you think a bit more information would help understanding your
assertion? Which "part of the specification of C++" did you read? What
in it suggested to you the validity of your code? Once you "made this
up", what was the reaction of your compiler when you fed it your code?

V
--
I do not respond to top-posted replies, please don't ask

Alain Ketterlin

unread,
Mar 14, 2016, 11:39:46 AM3/14/16
to
r...@zedat.fu-berlin.de (Stefan Ram) writes:

> I read a part of the specification of C++. It suggests than
> one can use »delete« outside of a class! I never saw this
> before, but I made this up:

It lets you forbid the use of a particular template instanciation.

template <typename T> void f(T x) {...} // Call f on everything
void f(int) = delete; // except ints

Or disallows implicit (silent) type casts:

void f(double x) { ... }
void f(int) = delete;

-- Alain.

Victor Bazarov

unread,
Mar 14, 2016, 11:58:53 AM3/14/16
to
On 3/14/2016 11:39 AM, Alain Ketterlin wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> I read a part of the specification of C++. It suggests than
>> one can use »delete« outside of a class! I never saw this
>> before, but I made this up:
>
> It lets you forbid the use of a particular template instanciation.
>
> template <typename T> void f(T x) {...} // Call f on everything
> void f(int) = delete; // except ints

Shouldn't this "definition" be a template declaration, though? I.e.

template<> void f(int) = delete;

?

> Or disallows implicit (silent) type casts:
>
> void f(double x) { ... }
> void f(int) = delete;
>
> -- Alain.
>

Alain Ketterlin

unread,
Mar 14, 2016, 12:12:14 PM3/14/16
to
Victor Bazarov <v.ba...@comcast.invalid> writes:

> On 3/14/2016 11:39 AM, Alain Ketterlin wrote:
>> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>>
>>> I read a part of the specification of C++. It suggests than
>>> one can use »delete« outside of a class! I never saw this
>>> before, but I made this up:
>>
>> It lets you forbid the use of a particular template instanciation.
>>
>> template <typename T> void f(T x) {...} // Call f on everything
>> void f(int) = delete; // except ints
>
> Shouldn't this "definition" be a template declaration, though? I.e.
>
> template<> void f(int) = delete;

Yes, you're right.

I finally tested this and my compiler didn't complain, in either case
(unless I call f(1), of course). I even tried putting both (without
complaint). When calling f(1) the compiler selected the non-template
version to tell me I wasn't allowed to call f(int). I don't know the
exact rule (or forgot it).

Anyway, thanks for the correction.

-- Alain.
0 new messages