Classes, objects, constructors, enums, code is down, not compiling

Good evening,

This is a homework assignment. I understand these concepts in theory, but I'm having a hard time combining them into something that works.

I am getting errors trying to compile:

no matching function for call to Date::Date()
no match for 'operator<<' (operand types are 'std::basic_ostream...... etc
reptile, frog, polly, all not declared in this scope (in main)

(Some of these errors may be my IDE/compiler as it's giving me errors with getchar and fflush... I can also try in xcode).

Any help would be greatly appreciated. I've been looking at this for far longer than I care to admit :)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 

#include<iostream>
#include<iomanip>
#include<string>



using namespace std;

class Date      //composed class
{
	private:

        int month;
        int day;
        int year;

    public:
        Date(int m, int d, int y)
        {
            month=m;
            day=d;
            year=y;
        }

    void SetDate()
    {
        month=1;
        day=1;
        year=2015;

        cout << "Month: ";
        cin >> month;
        cout << "/n Day: ";
        cin >> day;
        cout << "/n Year: ";
        cin >> year;


    }


	void ShowDate()
	{
        if (month<10)
            cout << "0" << month;
        else
            cout << month;
        if (day<10)
            cout << "/0" << day;
        else
            cout << day;
        cout << "/" << year;
    }

    ~Date();
};
Last edited on
> no matching function for call to Date::Date()
Date someDate;
¿what's the state of `someDate'?

I don't understand you. Judging by Mammal fido(mammal, dog, "Jim", someDate, 3); you do know how to construct objects.
... you also seem to know about initialization lists...


> no match for 'operator<<' (operand types are 'std::basic_ostream...... etc
`etc'... that's precisely where the information is, in your `etc'
you didn't even provide line numbers.


> reptile, frog, polly, all not declared in this scope
you purposely declare them inside of a class, and with a non-public especifier.
¿then you wonder why can't access them outside?
It looks like your Date class will need a copy constructor and a default constructor.

In Animal::Write you try to stream the return value from ShowData() but it has void return type.

in main() you are trying to access the enums from Animal; firstly, as ne555 says, the are not public so this will never work, make them public! Even then it wont work, because the enums are inside the Animal class. You will need Animal::bird to access those (after they are public).

@117 you redeclare outfile when it was already a parameter

Some of these errors may be my IDE/compiler as it's giving me errors with getchar and fflush

no, it will all be your code :) errors like that just mean that you haven't included something that you are trying to use.


fixing the few points i have made above should make the error list a bit more readable. But all in all you need to get cracking on those error and warning messages. Take them one at a time and just keep hammering away at them. Its as big a part of the job as the coding is. never let that list get big because it will demoralise you.

Some of them are simple issues that you can fix yourself but require some careful reading of the output to see what the actual error is. Especially the ones that are reported near template problems, template warning generate lots of output and can be difficult to read, you just have to be strong willed and try to isolate a message in the output and concentrate on that.

example
107:52: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'void')
the clue here is 'void' why are you trying to stream a void? Obviously you're not deliberately trying to stream a void, so how did the void get in there? a quick check shows that ShowData() returns a void.

In short, dont left the amount of build errors put you off. Just keep chipping away at them.

Just as a tip here, compile often! dont write reams of code and then have to sit through reams of errors. compile often and clear as many warnings/errors as you can before writing more.



Last edited on
Thanks Jaybob66, just needed a fresh pair of eyes :)

You were right about the void return type. Changed to float, no more errors.

Also added Animal::bird to the appropriate places in main, and now that's no longer giving me any errors.

Still stuck on the copy constructor. Maybe I slept through that class, I can't seem to wrap my head around what it's supposed to do and WHY it's needed.

I'll keep plugging away. Thank you SO much for your help!
Last edited on
I cant see your code now, you've removed the lines that had the error.

as a tip, dont edit the code, just repost it, unless its huge of course :)

Off the top of my head i think its because you pass the Date by value, so a copy will need to be made. you can prove/disprove this by changing the parameter to a reference.
Topic archived. No new replies allowed.