sepp2k's Profile User Rating: *****

Reputation: 2113 Grandmaster
Group:
Mentors
Active Posts:
3,245 (2.74 per day)
Joined:
21-June 11
Profile Views:
51,047
Last Active:
User is offline Private
Currently:
Offline

Previous Fields

Country:
DE
OS Preference:
Linux
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
C/C++, Functional Programming, Java, Python, Computer Science
Icon   sepp2k has not set their status

Posts I've Made

  1. In Topic: Help: Pointer to a nameless structure

    Posted 16 Sep 2014

    Yes, but that's not because of the clone function - it's because free_throws is not a reference, so free_throws test = ...; calls the copy constructor no matter what's to the right of the equals sign (as long as it's of type free_throws that is).

    The same thing happens when you define clone as return ft; or if you don't call clone at all and you just do free_throws test = freethrows;.

    Really defining something like a clone function makes little sense in C++. You always get a copy unless you use a pointer or reference, so whenever you want a copy you can just not use a pointer/reference and that's it. No need for a function.
  2. In Topic: Help: Pointer to a nameless structure

    Posted 16 Sep 2014

    That version doesn't clone anything though. It just returns a reference to the object that was passed in (and could be more concisely written as just return ft;).
  3. In Topic: Help: Pointer to a nameless structure

    Posted 16 Sep 2014

    View Postkenryuakuma, on 17 September 2014 - 01:57 AM, said:

    this is a code snippet extracted from C++ Primer Plus book. However, it is really confusing.


    That's because it's wrong. If your book really presents that as correct code (and not an example of what not to do), you should consider getting a different book.

    Quote

    as far as I know, a pointer has to point to a memory address, and it is best to initialize it when it is declared. However, according to the code snippet above, the pt isn't initialized to any address. Isn't it dangerous when we declare a pointer without initializing it before we use it?


    It is undefined behavior, yes. That code will very likely crash when you run it.

    Quote

    free_throw * pt = new three_throw; 
    
    // or
    
    free_throw * pt = & ft;
    
    


    Exactly.

    View PostCTphpnwb, on 17 September 2014 - 02:32 AM, said:

    The next line sets it to the address referred to by ft.


    No, it doesn't.
  4. In Topic: Ruby - Compare Integers by Divisiblity of 2

    Posted 15 Sep 2014

    On second thought it looks like you might have intended to create a wrapper class around integers. That would explain the Integer.new bit. If so, you must not name your class Integer. Integer already exists.
  5. In Topic: Ruby - Compare Integers by Divisiblity of 2

    Posted 15 Sep 2014

    Well, I've told you what the situation is. If you're really supposed to mess with the Integer class (and only the Integer class), your assignment is simply impossible to solve.

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
15
Programming Languages:
Haskell, Ruby, OCaml, SML, F#, Scala, Racket/Scheme, Vala, C#, C++, Java

Contact Information

E-mail:
Private
ICQ:
ICQ  205544826
Jabber:
Jabber  sexykane86@jabber.ccc.de