Is this valid c++?

Discussion in 'C++' started by dec4106, Nov 9, 2011.

  1. dec4106

    dec4106 Guest

    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?
     
    dec4106, Nov 9, 2011
    #1
    1. Advertising

  2. 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.
     
    Richard Damon, Nov 9, 2011
    #2
    1. Advertising

  3. dec4106 <> 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.
     
    Alain Ketterlin, Nov 9, 2011
    #3
  4. dec4106

    Jorgen Grahn Guest

    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 .
     
    Jorgen Grahn, Nov 9, 2011
    #4
  5. 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
     
    Victor Bazarov, Nov 9, 2011
    #5
  6. dec4106

    Krice Guest

    On 9 marras, 17:55, Alain Ketterlin <-strasbg.fr>
    wrote:
    > Yes, it lets the compiler generate the ctor for you, with default
    > behavior.


    What is that default behaviour?
     
    Krice, Nov 10, 2011
    #6
  7. Krice <> wrote:
    > On 9 marras, 17:55, Alain Ketterlin <-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).
     
    Juha Nieminen, Nov 10, 2011
    #7
  8. dec4106

    Jorgen Grahn Guest

    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 .
     
    Jorgen Grahn, Nov 10, 2011
    #8
  9. 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
     
    Victor Bazarov, Nov 10, 2011
    #9
  10. dec4106

    Jorgen Grahn Guest

    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 .
     
    Jorgen Grahn, Nov 12, 2011
    #10
  11. On Nov 9, 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?


    I think this is from one of my posts.

    Ironically, considering the rest of this thread, I don't even have a C+
    +11 compiler (or a system ready to use one). I'm learning C++11 from
    web sites and Usenet posts.

    I, nor anyone else, can define "default" in an example since it's a
    keyword!

    Daryle W.
     
    Daryle Walker, Nov 13, 2011
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aschel Kritsos

    Valid file types

    Aschel Kritsos, Nov 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    619
  2. Ajit
    Replies:
    1
    Views:
    3,683
    Victor Garcia Aprea [MVP]
    Apr 24, 2004
  3. CT

    vbc is not valid command

    CT, Oct 30, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,925
  4. Pial
    Replies:
    6
    Views:
    52,532
    Nassos
    Apr 28, 2005
  5. MM
    Replies:
    3
    Views:
    466
    Kai Harrekilde-Petersen
    Jun 19, 2004
Loading...

Share This Page