compile error

Discussion in 'C++' started by pagantom, Dec 17, 2006.

  1. pagantom

    pagantom Guest

    Hello. newbie here. need help. here's the text, compile errors are
    below. thanks

    class date
    {
    private:
    char *mo;
    int day, yr;

    public:
    date (char *m, int d, int y)
    {mo = new char[strlen(m)+1];
    strcpy(mo, m);
    day = d;
    yr = y;}

    date(const date &obj)
    {mo = new char[strlen(obj.mo)+1];
    strcpy(mo, obj.mo);
    day = obj.day;
    yr = obj.yr;}

    ~date()
    {delete[] mo;}

    const char *getMo()
    {return mo;}

    int getDay()
    {return day;}

    int getYr()
    {return yr;}

    void operator=(const date &right)
    { delete [] mo;
    mo = new char[strlen(right.mo) + 1];
    strcpy(mo, right.mo);
    day = right.day;
    yr = right.yr;}
    };

    class time:public date
    {
    private:
    int hr, min, sec;

    public:

    time (int hh, int mm, int ss)
    {hr = hh;
    min = mm;
    sec = ss;}

    time(const time &obj)
    {hr = obj.hr;
    min = obj.min;
    sec = obj.sec;}

    int getHour()
    {return hr;}

    int getMin()
    {return min;}

    int getSec()
    {return sec;}
    };

    class date
    {
    private:
    char *mo;
    int day, yr;

    public:
    date (char *m, int d, int y)
    {mo = new char[strlen(m)+1];
    strcpy(mo, m);
    day = d;
    yr = y;}

    date(const date &obj)
    {mo = new char[strlen(obj.mo)+1];
    strcpy(mo, obj.mo);
    day = obj.day;
    yr = obj.yr;}

    ~date()
    {delete[] mo;}

    const char *getMo()
    {return mo;}

    int getDay()
    {return day;}

    int getYr()
    {return yr;}

    void operator=(const date &right)
    { delete [] mo;
    mo = new char[strlen(right.mo) + 1];
    strcpy(mo, right.mo);
    day = right.day;
    yr = right.yr;}
    };

    class time:public date
    {
    private:
    int hr, min, sec;

    public:

    time (int hh, int mm, int ss)
    {hr = hh;
    min = mm;
    sec = ss;}

    time(const time &obj)
    {hr = obj.hr;
    min = obj.min;
    sec = obj.sec;}

    int getHour()
    {return hr;}

    int getMin()
    {return min;}

    int getSec()
    {return sec;}
    };

    Compile errors

    In constructor `time::time(int, int, int)':
    error: no matching function for call to `date::date()'
    note: candidates are: date::date(const date&)
    date::date(char*, int, int)

    In copy constructor `time::time(const time&)':
    error: no matching function for call to `date::date()'
    candidates are: date::date(const date&)
    date::date(char*, int, int)
     
    pagantom, Dec 17, 2006
    #1
    1. Advertising

  2. pagantom

    kwikius Guest

    pagantom wrote:
    > Hello. newbie here. need help. here's the text, compile errors are
    > below. thanks


    You need to add a constructor to your dat class that takes no
    parameters, or use one of the constructors you have defined with its
    parameters instead.

    regards
    Andy Little
     
    kwikius, Dec 17, 2006
    #2
    1. Advertising

  3. pagantom

    kwikius Guest

    pagantom wrote:
    > Hello. newbie here. need help. here's the text, compile errors are
    > below. thanks


    You need to add a constructor to your dat class that takes no
    parameters, or use one of the constructors you have defined with its
    parameters instead.

    regards
    Andy Little
     
    kwikius, Dec 17, 2006
    #3
  4. pagantom

    zouyongbin Guest

    "pagantom дµÀ£º
    "
    > Hello. newbie here. need help. here's the text, compile errors are
    > below. thanks


    The base class needs to be initialized with a default constructor here.
     
    zouyongbin, Dec 17, 2006
    #4
  5. pagantom

    pagantom Guest

    On Dec 17, 9:40 am, "zouyongbin" <> wrote:
    > "pagantom 写é“:
    > "
    >
    > > Hello. newbie here. need help. here's the text, compile errors are
    > > below. thanksThe base class needs to be initialized with a default constructor here.


    thanks, that did the trick. i added a main, but i'm getting more
    compliation errors.
    why are the "time" instances not being created?

    int main()
    {
    time first("January", 1, 2007);

    time second("January", 2, 2007);

    time reverse = first;

    cout << "first date = " << first.getMo();
    cout << "/" << first.getDay();
    cout << "/" << first.getYr() << endl;

    cout << "second date = " << second.getMo();
    cout << "/" << second.getDay();
    cout << "/" << second.getYr() << endl;

    reverse = second;
    second = first;

    cout << "now first date = " << reverse.getMo();
    cout << "/" << reverse.getDay();
    cout << "/" << reverse.getYr() << endl;

    cout << "now second date = " << second.getMo();
    cout << "/" << second.getDay();
    cout << "/" << second.getYr() << endl;

    int main()
    {
    time first("January", 1, 2007);

    time second("January", 2, 2007);

    time reverse = first;

    cout << "first date = " << first.getMo();
    cout << "/" << first.getDay();
    cout << "/" << first.getYr() << endl;

    cout << "second date = " << second.getMo();
    cout << "/" << second.getDay();
    cout << "/" << second.getYr() << endl;

    reverse = second;
    second = first;

    cout << "now first date = " << reverse.getMo();
    cout << "/" << reverse.getDay();
    cout << "/" << reverse.getYr() << endl;

    cout << "now second date = " << second.getMo();
    cout << "/" << second.getDay();
    cout << "/" << second.getYr() << endl;

    In function `int main()':
    error: expected `;' before "first"
    statement is a reference, not call, to function `time'
    error: expected `;' before "second"
    warning: statement is a reference, not call, to function `time'
    expected `;' before "reverse"
    statement is a reference, not call, to function `time'
     
    pagantom, Dec 17, 2006
    #5
  6. pagantom

    Default User Guest

    pagantom wrote:


    > int main()
    > {
    > time first("January", 1, 2007);
    >
    > time second("January", 2, 2007);
    >
    > time reverse = first;


    > In function `int main()':
    > error: expected `;' before "first"
    > statement is a reference, not call, to function `time'
    > error: expected `;' before "second"
    > warning: statement is a reference, not call, to function `time'
    > expected `;' before "reverse"
    > statement is a reference, not call, to function `time'


    time() is a function, not a datatype. What is it you are trying to do?



    Brian

    --
    Please don't top-post. Your replies belong following or interspersed
    with properly trimmed quotes. See the majority of other posts in the
    newsgroup, or:
    <http://www.caliburn.nl/topposting.html>
     
    Default User, Dec 17, 2006
    #6
  7. pagantom

    Micah Cowan Guest

    Default User wrote:
    > pagantom wrote:
    >
    >
    > > int main()
    > > {
    > > time first("January", 1, 2007);
    > >
    > > time second("January", 2, 2007);
    > >
    > > time reverse = first;

    >
    > > In function `int main()':
    > > error: expected `;' before "first"
    > > statement is a reference, not call, to function `time'
    > > error: expected `;' before "second"
    > > warning: statement is a reference, not call, to function `time'
    > > expected `;' before "reverse"
    > > statement is a reference, not call, to function `time'

    >
    > time() is a function, not a datatype. What is it you are trying to do?


    Well... no, std::time() is a function, but he hasn't #included <ctime>
    or imported the standard namespace, so no immediate problem, though
    it's still probably a pretty bad idea...

    </pedantry> :)
     
    Micah Cowan, Dec 17, 2006
    #7
  8. pagantom

    Default User Guest

    Micah Cowan wrote:

    >
    > Default User wrote:
    > > pagantom wrote:
    > >
    > >
    > > > int main()
    > > > {
    > > > time first("January", 1, 2007);
    > > >
    > > > time second("January", 2, 2007);
    > > >
    > > > time reverse = first;

    > >
    > > > In function `int main()':
    > > > error: expected `;' before "first"
    > > > statement is a reference, not call, to function `time'
    > > > error: expected `;' before "second"
    > > > warning: statement is a reference, not call, to function `time'
    > > > expected `;' before "reverse"
    > > > statement is a reference, not call, to function `time'

    > >
    > > time() is a function, not a datatype. What is it you are trying to
    > > do?

    >
    > Well... no, std::time() is a function, but he hasn't #included <ctime>
    > or imported the standard namespace, so no immediate problem, though
    > it's still probably a pretty bad idea...
    >
    > </pedantry> :)


    You were insufficiently pedantic. The C standard library and headers
    that place the identifiers in the global namespace are still standard,
    even though deprecated. So time() is a function, although the standard
    states that it's as if there were an explicit using-declaration.

    The point about headers is well taken, in fact the program shown had no
    headers at all.



    Brian
     
    Default User, Dec 17, 2006
    #8
  9. pagantom

    Micah Cowan Guest

    Default User wrote:
    > Micah Cowan wrote:
    > > Default User wrote:


    > > > time() is a function, not a datatype. What is it you are trying to
    > > > do?

    > >
    > > Well... no, std::time() is a function, but he hasn't #included <ctime>
    > > or imported the standard namespace, so no immediate problem, though
    > > it's still probably a pretty bad idea...
    > >
    > > </pedantry> :)

    >
    > You were insufficiently pedantic. The C standard library and headers
    > that place the identifiers in the global namespace are still standard,
    > even though deprecated. So time() is a function, although the standard
    > states that it's as if there were an explicit using-declaration.


    That's only true if you #include <time.h> instead of <ctime>, no? (Not
    that real-world implementations always work like that, which is part of
    why it's a bad idea...)

    -Micah
     
    Micah Cowan, Dec 19, 2006
    #9
    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. Nagaraj
    Replies:
    1
    Views:
    913
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,417
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    467
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    527
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    566
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page