I get no matching function for call to and more

Mar 8, 2020 at 2:18pm
He everyone, I am a beginner and I just finished the OOP part(from a course on web) of C++ and I started a little project about a movie fanatics. I got some errors that I will put here, and the code. If is hard to copy, then you can download the code files from here: https://ufile.io/pbht2fs6

Here are some of the errors that I don't know how to fix(if you run the code you will get like 6 errors):
1
2
3
4
5
6
7
8
9
10
11
In function 'void add_movie(Movies&, std::__cxx11::string, std::__cxx11::string, int)':error: no matching function for call to 'Movies::add_movie(std::__cxx11::string&)'
     if(movies.add_movie(name)){

note: candidate: bool Movies::add_movie(std::__cxx11::string, std::__cxx11::string, int)
     bool add_movie(std::string name, std::string rating, int watched);

error: no match for 'operator==' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'int')
         if(movie.get_name() == 0){

note: candidate: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
     operator==(const istreambuf_iterator<_CharT, _Traits>& __a,


Here is the code of main:
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
  #include <iostream>
#include "Movies.h"

void increment_watched(Movies &movies, std::string name);
void add_movie(Movies &movies, std::string name, std::string rating, int watched);

void increment_watched(Movies &movies, std::string name)
{
    if(movies.increment_watched(name)){
        std::cout << name << " watch incremented!" << std::endl;
    } else {
        std::cout << name << " not found!" << std::endl;
    }
}

void add_movie(Movies &movies, std::string name, std::string rating, int watched)
{
    if(movies.add_movie(name)){
        std::cout << name << " was added!" << std::endl;
    } else {
        std::cout << name << " already exists!" << std::endl;
    }
}

int main() {
    Movies my_movies;
    my_movies.display();

    add_movie(my_movies, "Legacies", "G", 100);
    add_movie(my_movies, "Dark Knight", "PG", 6);
    add_movie(my_movies, "We are Millers", "PG-13", 23);
    my_movies.display();

    add_movie(my_movies, "We are Millers", "PG-13", 23);
    add_movie(my_movies, "Ice Age", "PG", 12);
    my_movies.display();

    increment_watched(my_movies, "Legacies");
    increment_watched(my_movies, "Ice Age");
    my_movies.display();
    increment_watched(my_movies, "XXX");
    return 0;
}


Here is the code of Movie.h
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
#ifndef _MOVIE_H_
    #define _MOVIE_H_

    #include <string>

    class Movie {
    private:
        std::string name;
        std::string rating;
        int watched;

    public:
        Movie(std::string name, std::string rating, int watched);
        Movie(const Movie &source);
        ~Movie();

        void set_name(std::string name)
        {
            this->name = name;
        }

        std::string get_name() const
        {
            return name;
        }

        void set_rating(std::string rating)
        {
            this->rating = rating;
        }

        std::string get_rating() const
        {
            return rating;
        }

        void set_watched(int watched)
        {
            this->watched = watched;
        }

        int get_watched() const
        {
            return watched;
        }

        void increment_watched()
        {
            ++watched;
        }

        void display() const;
    };



    #endif //_MOVIE_H_ 


Here is the code of Movie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "Movie.h"
#include <iostream>

Movie::Movie(std::string name, std::string rating, int watched)
        : name(name), rating(rating), watched(watched){

}

Movie::Movie(const Movie &source)
        :Movie(source.name, source.rating, source.watched){

}

Movie::~Movie() {

}

void Movie::display() const{
    std::cout << "Movie's name: " << name << " ,rating: " << rating << " and watched for: " << watched << " times!" << std::endl;
}


Here is the code for Movies.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef _MOVIES_H_
#define _MOVIES_H_

#include "Movie.h"
#include <vector>

class Movies {
private:
    std::vector<Movie> movies;

public:
    Movies();
    ~Movies();

    bool add_movie(std::string name, std::string rating, int watched);
    bool increment_watched(std::string name);
    void display() const;
};


#endif //_MOVIES_H_ 


Here is the code of Movies.cpp
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
#include "Movies.h"
#include <iostream>

Movies::Movies() {

}

Movies::~Movies() {

}

bool Movies::add_movie(std::string name, std::string rating, int watched)
{
    for(const Movie &movie: movies){
        if(movie.get_name() == 0){
            return false;
        }
        Movie temp{name, rating, watched};
        movies.push_back(temp);
        return true;
        }

}


bool Movies::increment_watched(std::string name)
{
    for(Movie &movie: Movies){
        if(Movie.get_name == name){
            Movie.incremed_watched();
            return true;
        }
        return false;
    }
}

void Movies::display() const
{
    if(movies.size() == 0){
        std::cout << "Sorry, no movies to show!" << std::endl;
    } else {
        std::cout << "===================================" << std::endl;
        for(const auto &Movie: Movies)
            Movie.display();
        std::cout << "===================================" << std::endl;
    }
}
Mar 8, 2020 at 3:53pm
You are going to drive yourself and all of us guano loco having classes named movie and movies.

regardless, the problem is that in main
you try to call this:
bool Movies::add_movie(std::string name, std::string rating, int watched)
with
add_movie(name); ^^^ it needs more parameters than just this 1...
Mar 8, 2020 at 5:14pm
@jonnin thank you for your help, but after i edited that add_movie(name), i get new errors on line 29 from Movies.cpp (if(Movie.get_name == name)) at '==' operand that says:
1
2
 error: no match for 'operator==' (operand types are '<unresolved overloaded function type>' and 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}')
         if(movie.get_name == name){ 
Mar 8, 2020 at 6:19pm
focus. If the message is too cryptic, look at the line it complains about with a clear mind and you will see it. The message is telling you (function and string comparison does not exist) but it can take a while to get used to reading those.

get_name is a function: where is its () ??
try movie.get_name() == name

Topic archived. No new replies allowed.