Problem creating movie archive

I wish to create a movie archive, in wich I can store the movie titel and what kind of media it's on (DVD, Blueray, VHS).

I tried do it like this, after reading a lot on google etc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

class Film
{
    public:
        string namn;
        string titel;
        string typ;
        Film(string, string);
};

int main()
{
    Film nyFilm(string, string);
    getline(cin, nyFilm.name);
}


It will not compile, but I can not figure out what's the problem? Can someone please tell me what I am doing wrong?

Thanks in advance!
you cannot create an object like you did in line 15. you have to replace both "string" with actual strings, or make default names. Also you need to implement your constructor.
Edit:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;

class Film
{
    public:
        string name;
        string type;
        Film(string name,  string type);
};

Film::Film(string name="",  string type="") {
	this->name=name;
	this->type=type;
}

int main()
{
    Film nyFilm;
    getline(cin, nyFilm.name);
}
}

Edit: Should work
Last edited on
- defined your constructor
- learn how to pass to functions

just for reminder :)
Last edited on
The compiler returns error on line
9, 12, 13, 14...

9|error: after previous specification in 'Film::Film(std::string, std::string)'|

12|error: default argument given for parameter 2 of 'Film::Film(std::string, std::string)'|

13|error: request for member 'name' in 'this', which is of non-class type 'Film* const'|

14|error: request for member 'type' in 'this', which is of non-class type 'Film* const'|

20|error: request for member 'name' in 'nyFilm', which is of non-class type 'Film()'|

Is there an #include missing? It's a lot of errors and I can not figure it out....

Thanks anyway! =)
The code above should work now, hope it helps.
Works like a charm! Thank you very much!

I will probably be back with more problems when I get futher on with my archive.

Thank you!
Topic archived. No new replies allowed.