Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is this valid c++?

Reply
Thread Tools

Is this valid c++?

 
 
dec4106
Guest
Posts: n/a
 
      11-09-2011
Earlier today I came across a code example that looked something like
this:


template <typename T, unsigned S>
class MyClass
{
public:
MyClass() = default;
...

"default" is not defined anywhere in the example. I've never seen an
expression like this before and don't understand how it could work,
and haven't been able to make it work. Is this a C++11 thing?

 
Reply With Quote
 
 
 
 
Richard Damon
Guest
Posts: n/a
 
      11-09-2011
On 11/9/11 10:29 AM, dec4106 wrote:
> Earlier today I came across a code example that looked something like
> this:
>
>
> template<typename T, unsigned S>
> class MyClass
> {
> public:
> MyClass() = default;
> ...
>
> "default" is not defined anywhere in the example. I've never seen an
> expression like this before and don't understand how it could work,
> and haven't been able to make it work. Is this a C++11 thing?
>


Yes, that is a new C++11 construct, it tells the compiler to make a
standard default constructor MyClass() with the "default"
implementation, even if some other constructor is defined that would
suppress the generation of the default constructor.
 
Reply With Quote
 
 
 
 
Alain Ketterlin
Guest
Posts: n/a
 
      11-09-2011
dec4106 <(E-Mail Removed)> writes:

> template <typename T, unsigned S>
> class MyClass
> {
> public:
> MyClass() = default;
> ...
>
> "default" is not defined anywhere in the example. I've never seen an
> expression like this before and don't understand how it could work,
> and haven't been able to make it work. Is this a C++11 thing?


Yes, it lets the compiler generate the ctor for you, with default
behavior.

-- Alain.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-09-2011
On Wed, 2011-11-09, Richard Damon wrote:
> On 11/9/11 10:29 AM, dec4106 wrote:
>> Earlier today I came across a code example that looked something like
>> this:
>>
>>
>> template<typename T, unsigned S>
>> class MyClass
>> {
>> public:
>> MyClass() = default;
>> ...
>>
>> "default" is not defined anywhere in the example. I've never seen an
>> expression like this before and don't understand how it could work,
>> and haven't been able to make it work. Is this a C++11 thing?
>>

>
> Yes, that is a new C++11 construct, it tells the compiler to make a
> standard default constructor MyClass() with the "default"
> implementation, even if some other constructor is defined that would
> suppress the generation of the default constructor.


I hope this doesn't become the norm -- mixing C++11 into examples,
discussions etc -- just yet. I bet most of us cannot switch, due
to having to support some system which doesn't have a bleeding edge
compiler yet. (My Debian Stable systems have gcc 4.4, which
implements maybe 50%.)

C++11 is great, and it seems it will propagate out to the end users
much faster than C++98 did ... but we have to survive while waiting
for it, too.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-09-2011
On 11/9/2011 12:48 PM, Jorgen Grahn wrote:
> On Wed, 2011-11-09, Richard Damon wrote:
>> On 11/9/11 10:29 AM, dec4106 wrote:
>>> Earlier today I came across a code example that looked something like
>>> this:
>>>
>>>
>>> template<typename T, unsigned S>
>>> class MyClass
>>> {
>>> public:
>>> MyClass() = default;
>>> ...
>>>
>>> "default" is not defined anywhere in the example. I've never seen an
>>> expression like this before and don't understand how it could work,
>>> and haven't been able to make it work. Is this a C++11 thing?
>>>

>>
>> Yes, that is a new C++11 construct, it tells the compiler to make a
>> standard default constructor MyClass() with the "default"
>> implementation, even if some other constructor is defined that would
>> suppress the generation of the default constructor.

>
> I hope this doesn't become the norm -- mixing C++11 into examples,
> discussions etc -- just yet. I bet most of us cannot switch, due
> to having to support some system which doesn't have a bleeding edge
> compiler yet. (My Debian Stable systems have gcc 4.4, which
> implements maybe 50%.)
>
> C++11 is great, and it seems it will propagate out to the end users
> much faster than C++98 did ... but we have to survive while waiting
> for it, too.


And how long do you think we should wait?

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Krice
Guest
Posts: n/a
 
      11-10-2011
On 9 marras, 17:55, Alain Ketterlin <(E-Mail Removed)-strasbg.fr>
wrote:
> Yes, it lets the compiler generate the ctor for you, with default
> behavior.


What is that default behaviour?
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      11-10-2011
Krice <(E-Mail Removed)> wrote:
> On 9 marras, 17:55, Alain Ketterlin <(E-Mail Removed)-strasbg.fr>
> wrote:
>> Yes, it lets the compiler generate the ctor for you, with default
>> behavior.

>
> What is that default behaviour?


All member objects are default-constructed (after which the derived class
default constructor is called if this was really an object of a derived
class).
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-10-2011
On Wed, 2011-11-09, Victor Bazarov wrote:
> On 11/9/2011 12:48 PM, Jorgen Grahn wrote:
>> On Wed, 2011-11-09, Richard Damon wrote:
>>> On 11/9/11 10:29 AM, dec4106 wrote:
>>>> Earlier today I came across a code example that looked something like
>>>> this:
>>>>
>>>>
>>>> template<typename T, unsigned S>
>>>> class MyClass
>>>> {
>>>> public:
>>>> MyClass() = default;
>>>> ...
>>>>
>>>> "default" is not defined anywhere in the example. I've never seen an
>>>> expression like this before and don't understand how it could work,
>>>> and haven't been able to make it work. Is this a C++11 thing?
>>>>
>>>
>>> Yes, that is a new C++11 construct, it tells the compiler to make a
>>> standard default constructor MyClass() with the "default"
>>> implementation, even if some other constructor is defined that would
>>> suppress the generation of the default constructor.

>>
>> I hope this doesn't become the norm -- mixing C++11 into examples,
>> discussions etc -- just yet. I bet most of us cannot switch, due
>> to having to support some system which doesn't have a bleeding edge
>> compiler yet. (My Debian Stable systems have gcc 4.4, which
>> implements maybe 50%.)
>>
>> C++11 is great, and it seems it will propagate out to the end users
>> much faster than C++98 did ... but we have to survive while waiting
>> for it, too.

>
> And how long do you think we should wait?


I won't know until it happens (and I'll make sure to tell you).

It's subjective of course; I'm just saying I think we're not there yet,
for e.g. the reasons I listed above.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-10-2011
On 11/10/2011 3:20 PM, Jorgen Grahn wrote:
> On Wed, 2011-11-09, Victor Bazarov wrote:
>> On 11/9/2011 12:48 PM, Jorgen Grahn wrote:
>>> On Wed, 2011-11-09, Richard Damon wrote:
>>>> On 11/9/11 10:29 AM, dec4106 wrote:
>>>>> Earlier today I came across a code example that looked something like
>>>>> this:
>>>>>
>>>>>
>>>>> template<typename T, unsigned S>
>>>>> class MyClass
>>>>> {
>>>>> public:
>>>>> MyClass() = default;
>>>>> ...
>>>>>
>>>>> "default" is not defined anywhere in the example. I've never seen an
>>>>> expression like this before and don't understand how it could work,
>>>>> and haven't been able to make it work. Is this a C++11 thing?
>>>>>
>>>>
>>>> Yes, that is a new C++11 construct, it tells the compiler to make a
>>>> standard default constructor MyClass() with the "default"
>>>> implementation, even if some other constructor is defined that would
>>>> suppress the generation of the default constructor.
>>>
>>> I hope this doesn't become the norm -- mixing C++11 into examples,
>>> discussions etc -- just yet. I bet most of us cannot switch, due
>>> to having to support some system which doesn't have a bleeding edge
>>> compiler yet. (My Debian Stable systems have gcc 4.4, which
>>> implements maybe 50%.)
>>>
>>> C++11 is great, and it seems it will propagate out to the end users
>>> much faster than C++98 did ... but we have to survive while waiting
>>> for it, too.

>>
>> And how long do you think we should wait?

>
> I won't know until it happens (and I'll make sure to tell you).


<sarcasm> We'll all wait with baited breath. </sarcasm>

> It's subjective of course; I'm just saying I think we're not there yet,
> for e.g. the reasons I listed above.


<shrug> You're not there. I'm not there. Shouldn't preclude those who
want to discuss C++11 from talking about it and giving code snippets
with the language _a Standard for which has already been approved_.

The more "we" (as a c.l.c++ community) do the "mixing C++11 into
examples", the sooner it is learned by "us" (and that means you, as well).

I say, go for it! As an old Russian saying goes, to learn to swim one
must go into water.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-12-2011
On Thu, 2011-11-10, Victor Bazarov wrote:
> On 11/10/2011 3:20 PM, Jorgen Grahn wrote:
>> On Wed, 2011-11-09, Victor Bazarov wrote:
>>> On 11/9/2011 12:48 PM, Jorgen Grahn wrote:
>>>> On Wed, 2011-11-09, Richard Damon wrote:
>>>>> On 11/9/11 10:29 AM, dec4106 wrote:
>>>>>> Earlier today I came across a code example that looked something like
>>>>>> this:
>>>>>>
>>>>>>
>>>>>> template<typename T, unsigned S>
>>>>>> class MyClass
>>>>>> {
>>>>>> public:
>>>>>> MyClass() = default;
>>>>>> ...
>>>>>>
>>>>>> "default" is not defined anywhere in the example. I've never seen an
>>>>>> expression like this before and don't understand how it could work,
>>>>>> and haven't been able to make it work. Is this a C++11 thing?
>>>>>>
>>>>>
>>>>> Yes, that is a new C++11 construct, it tells the compiler to make a
>>>>> standard default constructor MyClass() with the "default"
>>>>> implementation, even if some other constructor is defined that would
>>>>> suppress the generation of the default constructor.
>>>>
>>>> I hope this doesn't become the norm -- mixing C++11 into examples,
>>>> discussions etc -- just yet. I bet most of us cannot switch, due
>>>> to having to support some system which doesn't have a bleeding edge
>>>> compiler yet. (My Debian Stable systems have gcc 4.4, which
>>>> implements maybe 50%.)
>>>>
>>>> C++11 is great, and it seems it will propagate out to the end users
>>>> much faster than C++98 did ... but we have to survive while waiting
>>>> for it, too.
>>>
>>> And how long do you think we should wait?

>>
>> I won't know until it happens (and I'll make sure to tell you).

>
> <sarcasm> We'll all wait with baited breath. </sarcasm>


I think you missed /my/ sarcasm above

>> It's subjective of course; I'm just saying I think we're not there yet,
>> for e.g. the reasons I listed above.

>
> <shrug> You're not there. I'm not there. Shouldn't preclude those who
> want to discuss C++11 from talking about it and giving code snippets
> with the language _a Standard for which has already been approved_.


Of course C++11 needs to be discussed et cetera like you say; I don't
propose to treat it as a second-class language for N more years.

I'm just afraid that while the early adopters are having fun with the
new features (and all the positive effects which come with that), the
big crowd of C++ users are partly left behind, some of them being
/more/ confused than they already were.

> The more "we" (as a c.l.c++ community) do the "mixing C++11 into
> examples", the sooner it is learned by "us" (and that means you, as well).
>
> I say, go for it! As an old Russian saying goes, to learn to swim one
> must go into water.


I'd like to, but my code has to compile & run on a few different
machines not under my direct control. When g++ 4.6 hits Debian Stable
is when I personally can consider flipping the -std=c++11 switch, or
whatever it's called. By that time, I expect most systems which have
C++98 today, will also have large parts of C++11 (because Debian isn't
known for it's bleeding-edge-ness).

(At work is another issue: as is often the case, I'm stuck with even
older tools there. But that's not new; I can't even use C99 there.)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not valid SSID name during setup using the wizard =?Utf-8?B?SE1WYWNhbmE=?= Wireless Networking 4 08-23-2005 05:38 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 3 04-27-2005 09:20 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 0 04-26-2005 06:41 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
Valid file types Aschel Kritsos ASP .Net 1 11-14-2003 05:13 PM



Advertisments