How to Implement Aggregation concept in C++

Discussion in 'C++' started by Rajen, Sep 6, 2006.

  1. Rajen

    Rajen Guest

    I have an Account class in which Date object is a member of it.
    When I created an account class:
    These errors are coming up:
    ////////
    :!g++ Account.cpp Account_main.cpp
    /tmp/cclWe0e4.o(.text+0x17): In function
    `Account::Account[not-in-charge]()':
    : undefined reference to `Date::Date[in-charge](int, int, int)'
    /tmp/cclWe0e4.o(.text+0x7d): In function
    `Account::Account[in-charge]()':
    : undefined reference to `Date::Date[in-charge](int, int, int)'
    /tmp/ccGYfdzi.o(.text+0x20): In function `main':
    : undefined reference to `Date::Date[in-charge](char*)'
    /tmp/ccGYfdzi.o(.text+0x16f): In function `main':
    : undefined reference to `Date::ToString(char*)'
    collect2: ld returned 1 exit status

    shell returned 1
    ////////

    Account_main.cpp is place where I create an Account object.
    Also please help in understanding these errors!!

    ********************************Account_main.cpp***************************
    #include <iostream>
    #include "Account.h"
    using namespace std;

    int main(int argc, char **argv)
    {
    char acAccDate[11];
    char acAccType[2];

    //Account oA1;
    //Date myDate("13-02-1988");
    Account oA1(1322,23432,"SB",1000.00,Date("15-5-1999"));
    //oA1.SetAccount(1322,23432,"SB",1000.00) : m_oDate("13-02-1988");

    cout << "Account Details:" << endl;
    cout << "No:" << oA1.GetAccNo() << endl;
    oA1.GetAccType(acAccType);
    cout << "Type:" << acAccType << endl;
    cout << "Balance:" << oA1.GetBalance() << endl;
    oA1.GetAccDate().ToString(acAccDate);
    cout << "Date:" << acAccDate << endl;

    return 0;
    }

    ********************************Account.cpp***********************************
    #include "Account.h"
    #include <cstring>
    Account::Account()
    {
    m_iCustId=0;
    SetAccNo(0);
    SetAccType("SB");
    SetBalance(1000.00);
    }

    Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    double dBalance, Date oDate): m_oDate(oDate)
    {
    m_iCustId = iCustId;
    SetAccNo(ulAccNo);
    SetAccType(acAccType);
    SetBalance(dBalance);
    /*m_oDate.m_iDay = oDate.m_iDay;
    m_oDate.m_iMonth= oDate.m_iMonth;
    m_oDate.m_iYear= oDate.m_iYear;*/
    }
    /*
    Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    double dBalance) : m_oDate(Date sDate)
    {
    m_iCustId = iCustId;
    SetAccNo(ulAccNo);
    SetAccType(acAccType);
    SetBalance(dBalance);
    }
    */

    void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
    *acAccType, double dBalance, Date oDate)
    {
    m_iCustId = iCustId;
    SetAccNo(ulAccNo);
    SetAccType(acAccType);
    SetBalance(dBalance);
    /*
    m_oDate.m_iDay = oDate.m_iDay;
    m_oDate.m_iMonth= oDate.m_iMonth;
    m_oDate.m_iYear= oDate.m_iYear;
    */
    }

    void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
    *acAccType, double dBalance)
    {
    m_iCustId = iCustId;
    SetAccNo(ulAccNo);
    SetAccType(acAccType);
    SetBalance(dBalance);
    }

    void Account::SetAccNo(unsigned long ulAccNo)
    {
    m_ulAccNo = ulAccNo;
    }

    /*Set the account type as given. By default set it as "SB"*/
    void Account::SetAccType(char *acAccType)
    {
    ( (strcasecmp(acAccType, "SB") == 0) && (strcasecmp(acAccType,
    "CA")==0) && (strcasecmp(acAccType, "RD")==0) && (strcasecmp(acAccType,
    "FD")==0) )
    ? strcpy(m_acAccType, acAccType) : strcpy(m_acAccType , "SB");
    }

    void Account::SetBalance(double dBalance)
    {
    m_dBalance = ( dBalance > 1000.00) ? dBalance : 1000.00;
    }

    unsigned long Account::GetAccNo() const
    {
    return m_ulAccNo;
    }

    void Account::GetAccType( char *sType ) const
    {
    strcpy(sType, m_acAccType);
    }

    double Account::GetBalance() const
    {
    return m_dBalance;
    }

    Date Account::GetAccDate() const
    {
    return this->m_oDate;
    }

    *************************************Account.h******************************
    #include "Date.h"
    #ifndef _ACCOUNT_H
    #define _ACCOUNT_H

    class Account
    {
    private:
    int m_iCustId;
    unsigned long m_ulAccNo;
    char m_acAccType[3];
    double m_dBalance;
    Date m_oDate;

    public:
    /*Constructor*/
    Account();
    Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    double dBalance, Date oDate);
    Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    double dBalance);

    /*Set Methods*/
    void SetAccount(int iCustId, unsigned long ulAccNo, char
    *acAccType, double dBalance, Date oDate);
    void SetAccount(int iCustId, unsigned long ulAccNo, char
    *acAccType, double dBalance);
    void SetCustId(int iCustId);
    void SetAccNo(unsigned long ulAccNo);
    void SetAccType( char *acAccType );
    void SetBalance(double dBalance);

    /*Get Methods*/
    //int GetCustId() const;
    unsigned long GetAccNo() const;
    void GetAccType( char *sType ) const;
    double GetBalance() const;
    Date GetAccDate() const;

    };

    #endif
    ******************************************************************************************
    That was the code.
    Please helpme!!
     
    Rajen, Sep 6, 2006
    #1
    1. Advertising

  2. Rajen wrote:
    > I have an Account class in which Date object is a member of it.
    > When I created an account class:
    > These errors are coming up:
    > ////////
    > :!g++ Account.cpp Account_main.cpp
    > /tmp/cclWe0e4.o(.text+0x17): In function
    > `Account::Account[not-in-charge]()':
    >> undefined reference to `Date::Date[in-charge](int, int, int)'

    > [...]


    "Undefined reference" usually means the compiler can see that you use
    a function, but it can't see the function itself (the definition, the
    body, the implementation). 'Date::Date' is a constructor. Did you
    show your compiler where the implemenation of 'Date' class is located?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Sep 6, 2006
    #2
    1. Advertising

  3. Rajen

    Rolf Magnus Guest

    Rajen wrote:

    > I have an Account class in which Date object is a member of it.
    > When I created an account class:
    > These errors are coming up:
    > ////////
    > :!g++ Account.cpp Account_main.cpp


    Try it the other way round.

    > /tmp/cclWe0e4.o(.text+0x17): In function
    > `Account::Account[not-in-charge]()':
    > : undefined reference to `Date::Date[in-charge](int, int, int)'
    > /tmp/cclWe0e4.o(.text+0x7d): In function
    > `Account::Account[in-charge]()':
    > : undefined reference to `Date::Date[in-charge](int, int, int)'
    > /tmp/ccGYfdzi.o(.text+0x20): In function `main':
    > : undefined reference to `Date::Date[in-charge](char*)'
    > /tmp/ccGYfdzi.o(.text+0x16f): In function `main':
    > : undefined reference to `Date::ToString(char*)'
    > collect2: ld returned 1 exit status
    >
    > shell returned 1
    > ////////
    >
    > Account_main.cpp is place where I create an Account object.
    > Also please help in understanding these errors!!
    >
    >

    ********************************Account_main.cpp***************************
    > #include <iostream>
    > #include "Account.h"
    > using namespace std;
    >
    > int main(int argc, char **argv)
    > {
    > char acAccDate[11];
    > char acAccType[2];
    >
    > //Account oA1;
    > //Date myDate("13-02-1988");
    > Account oA1(1322,23432,"SB",1000.00,Date("15-5-1999"));
    > //oA1.SetAccount(1322,23432,"SB",1000.00) : m_oDate("13-02-1988");
    >
    > cout << "Account Details:" << endl;
    > cout << "No:" << oA1.GetAccNo() << endl;
    > oA1.GetAccType(acAccType);
    > cout << "Type:" << acAccType << endl;
    > cout << "Balance:" << oA1.GetBalance() << endl;
    > oA1.GetAccDate().ToString(acAccDate);
    > cout << "Date:" << acAccDate << endl;
    >
    > return 0;
    > }
    >
    >

    ********************************Account.cpp***********************************
    > #include "Account.h"
    > #include <cstring>
    > Account::Account()
    > {
    > m_iCustId=0;
    > SetAccNo(0);
    > SetAccType("SB");
    > SetBalance(1000.00);
    > }
    >
    > Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    > double dBalance, Date oDate): m_oDate(oDate)
    > {
    > m_iCustId = iCustId;
    > SetAccNo(ulAccNo);
    > SetAccType(acAccType);
    > SetBalance(dBalance);
    > /*m_oDate.m_iDay = oDate.m_iDay;
    > m_oDate.m_iMonth= oDate.m_iMonth;
    > m_oDate.m_iYear= oDate.m_iYear;*/
    > }
    > /*
    > Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    > double dBalance) : m_oDate(Date sDate)
    > {
    > m_iCustId = iCustId;
    > SetAccNo(ulAccNo);
    > SetAccType(acAccType);
    > SetBalance(dBalance);
    > }
    > */
    >
    > void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
    > *acAccType, double dBalance, Date oDate)
    > {
    > m_iCustId = iCustId;
    > SetAccNo(ulAccNo);
    > SetAccType(acAccType);
    > SetBalance(dBalance);
    > /*
    > m_oDate.m_iDay = oDate.m_iDay;
    > m_oDate.m_iMonth= oDate.m_iMonth;
    > m_oDate.m_iYear= oDate.m_iYear;
    > */
    > }
    >
    > void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
    > *acAccType, double dBalance)
    > {
    > m_iCustId = iCustId;
    > SetAccNo(ulAccNo);
    > SetAccType(acAccType);
    > SetBalance(dBalance);
    > }
    >
    > void Account::SetAccNo(unsigned long ulAccNo)
    > {
    > m_ulAccNo = ulAccNo;
    > }
    >
    > /*Set the account type as given. By default set it as "SB"*/
    > void Account::SetAccType(char *acAccType)
    > {
    > ( (strcasecmp(acAccType, "SB") == 0) && (strcasecmp(acAccType,
    > "CA")==0) && (strcasecmp(acAccType, "RD")==0) && (strcasecmp(acAccType,
    > "FD")==0) )
    > ? strcpy(m_acAccType, acAccType) : strcpy(m_acAccType , "SB");
    > }
    >
    > void Account::SetBalance(double dBalance)
    > {
    > m_dBalance = ( dBalance > 1000.00) ? dBalance : 1000.00;
    > }
    >
    > unsigned long Account::GetAccNo() const
    > {
    > return m_ulAccNo;
    > }
    >
    > void Account::GetAccType( char *sType ) const
    > {
    > strcpy(sType, m_acAccType);
    > }
    >
    > double Account::GetBalance() const
    > {
    > return m_dBalance;
    > }
    >
    > Date Account::GetAccDate() const
    > {
    > return this->m_oDate;
    > }
    >
    >

    *************************************Account.h******************************
    > #include "Date.h"
    > #ifndef _ACCOUNT_H
    > #define _ACCOUNT_H
    >
    > class Account
    > {
    > private:
    > int m_iCustId;
    > unsigned long m_ulAccNo;
    > char m_acAccType[3];
    > double m_dBalance;
    > Date m_oDate;
    >
    > public:
    > /*Constructor*/
    > Account();
    > Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    > double dBalance, Date oDate);
    > Account(int iCustId, unsigned long ulAccNo, char *acAccType,
    > double dBalance);
    >
    > /*Set Methods*/
    > void SetAccount(int iCustId, unsigned long ulAccNo, char
    > *acAccType, double dBalance, Date oDate);
    > void SetAccount(int iCustId, unsigned long ulAccNo, char
    > *acAccType, double dBalance);
    > void SetCustId(int iCustId);
    > void SetAccNo(unsigned long ulAccNo);
    > void SetAccType( char *acAccType );
    > void SetBalance(double dBalance);
    >
    > /*Get Methods*/
    > //int GetCustId() const;
    > unsigned long GetAccNo() const;
    > void GetAccType( char *sType ) const;
    > double GetBalance() const;
    > Date GetAccDate() const;
    >
    > };
    >
    > #endif
    >

    ******************************************************************************************
    > That was the code.
    > Please helpme!!
     
    Rolf Magnus, Sep 6, 2006
    #3
  4. Rolf Magnus wrote:
    > Rajen wrote:
    >
    >> I have an Account class in which Date object is a member of it.
    >> When I created an account class:
    >> These errors are coming up:
    >> ////////
    >> :!g++ Account.cpp Account_main.cpp

    >
    > Try it the other way round.
    >
    >> [..]


    Did you *have* to quote the whole thing just to add one line?
     
    Victor Bazarov, Sep 6, 2006
    #4
  5. Rajen

    Rolf Magnus Guest

    Victor Bazarov wrote:

    > Rolf Magnus wrote:
    >> Rajen wrote:
    >>
    >>> I have an Account class in which Date object is a member of it.
    >>> When I created an account class:
    >>> These errors are coming up:
    >>> ////////
    >>> :!g++ Account.cpp Account_main.cpp

    >>
    >> Try it the other way round.
    >>
    >>> [..]

    >
    > Did you *have* to quote the whole thing just to add one line?


    Definitely! No, just kidding. I was in a rush and forget to cut out the
    source code.
     
    Rolf Magnus, Sep 6, 2006
    #5
    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. Rick Osborn

    Aggregation vs. composition

    Rick Osborn, Jan 23, 2004, in forum: Java
    Replies:
    11
    Views:
    57,987
    amitg_amity
    Aug 31, 2009
  2. Markos Charatzas

    Interfaces and aggregation

    Markos Charatzas, Jan 30, 2004, in forum: Java
    Replies:
    7
    Views:
    1,994
    BarryNL
    Feb 2, 2004
  3. Anonymous
    Replies:
    3
    Views:
    32,245
  4. Aff@n
    Replies:
    1
    Views:
    379
    Ian Collins
    Oct 16, 2006
  5. srinivas
    Replies:
    7
    Views:
    282
    Thomas 'PointedEars' Lahn
    Nov 18, 2005
Loading...

Share This Page