Class constructor

This is a discussion on Class constructor within the C++ Programming forums, part of the General Programming Boards category; Hello, I am trying to have the constructor for a class use the address of the object being created.. e.g. ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    67

    Question Class constructor

    Hello, I am trying to have the constructor for a class use the address of the object being created..

    e.g.

    Code:
    class test
    {
         test()
         {
               someFn(&this_object);
         }
    }
    
    test hello;
    how do I do that? &this doesn't work.

    thanks

    Edit: this is an address, so no need for the ampersand. Problem solved.
    Last edited by RobotGymnast; 09-22-2008 at 05:38 PM.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,472
    Edit: this is an address, so no need for the ampersand. Problem solved.
    And no need to pass the object to the constructor
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I don't believe he was wanting to pass the object to the constructor. I think he was instead wanting to pass this to a function.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,472
    Oh, yes. My bad.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  4. Calling constructor of the base class of a derived class..
    By CaptainPenguin in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2003, 12:47 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21