Data member passing

This is a discussion on Data member passing within the C++ Programming forums, part of the General Programming Boards category; Hi there, Could somebody please guide me with the procedure to pass the value of: a) A data member, defined ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    22

    Data member passing

    Hi there,

    Could somebody please guide me with the procedure to pass the value of:

    a) A data member, defined in one class, into another class
    b) A data member, defined in a function of a class, into another function of the same class

    Would gr8ly appreciate advise here.

    Best,
    wirefree101

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    I would say that depends on about a zillion different things. What exactly are you trying to achieve here? have you got an example of why you want to pass data around like that?

    Most commonly, passing individual data members around from one class to another is a symptom of bad design (Not always, but alot can start to go wrong when a member function begins directly reading & modifying members of a different class)

    There's almost certainly an alternative approach - if you give us details of what you're trying to do, someone may be able to suggest something.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    >A data member, defined in one class, into another class

    Interherence. You can define a data member as protected in a form of a 'base' class and use it in another class.
    I'm just trying to be a better person - My Name Is Earl

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,407
    Interherence.
    Err... do you mean "inheritance"?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Yes, sorry it was late when i typed that and I didnt notice.
    I'm just trying to be a better person - My Name Is Earl

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Appreciate the responses.

    Following are the specifics:

    - IDE generates 5 errors related, essentially, with the non-transferability/usage of:

    a) ‘bLocStr’ (defined in WrUAppUi.cpp) being referred to in MTMSExampleEngine.cpp.

    defined here...
    Code:
    File: WrUAppUi.cpp
    
    CWrUAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
        {
        switch (aEvent)
    ...
    ...
    TBuf16<128> bLocStr;
    ...
    used here...
    Code:
    File: CMtmsExampleEngine.cpp
    
    void CMtmsExampleEngine::CreateDraftSMSL(const TDesC& aAddress)
        {
    ...
    ...
    body.InsertL(0, bLocStr);
    ...

    b) ‘address’ (defined, & used, earlier in the same class) being referred to in HandleSessionEventL() of WrUAppUi.cpp

    defined here...
    Code:
    File: WrUAppUi.cpp
    
    void CWrUAppUi::HandleCommandL(TInt aCommand)
        {
    ...
    ...
    TBuf<30> address;
    GetNumber(address);
    iEngine->CreateDraftSMSL(address);
    ...
    used here...
    Code:
    File: WrUAppUi.cpp
    
    void CWrUAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
        {
        switch (aEvent)
    ...
    ...
    iEngine->CreateDraftNewSMSL(address);
    ...
    Would appreciate a prompt response.


    Best,
    wirefree101

  7. #7
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You cannot access local variables of one (member) function in another function.
    Make them class members or pass them as parameters.
    Kurt

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Thx for the response.

    Issue (b) has resolved by declaring 'address' as 'public' in WrUAppUi.h.

    However, with reference to issue (a) above, can you please advise me on how to pass value to other classes and use them there. (Note: TBuf16<128> bLocStr is defined in WruAppUi.cpp & assigned a value there. Now it needs to be used in CMtmsExampleEngine.cpp)

    Thx in advance,
    wirefree101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-07-2007, 11:24 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. typecasting data for parameter passing
    By daluu in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2004, 01:58 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM

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