error: no matching function for call to

I'm serious stuck and really need some help. I'm working on a calorie counter. It's a simple program that reads ingredients from a nutrient file and a recipe file. The nutrient file fields are name, amount, units, and calories. The recipe file fields are actual amount, units, and name. Not every ingredient in the nutrient file is used in the recipe. If both the name and unit matches, then it will print "total number of calories in one serving ..." If only some match, it will print "at least...."

The problem I'm having is with the search function. I'm trying to do a seq search using a function template to match the names and units but I keep getting a no match function for call to error. Deduction conflicting types for parameter 'T'. I take it 'T' is no reading that I'm trying to pass a string. I've tried removing T and put in string name but I still get the same error. I would appreciate it if someone will tell me what I'm missing. I've been working on this off and on for a while now.

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>

#include "vectorUtils.h"

using namespace std;

struct Nutrient
{
    std::string name;
    double num_units;
    std::string units;
    double calories;
    double calories_per_unit;

};

struct Recipe
{
    std::string name;
    std::string units;
    double num_units;
};



///Compute the number of calories in one serving of a recipe
void computeCalories (const char* nutrientFileName, const char* recipeFileName);



void computeCalories (const char* nutrientFileName, const char* recipeFileName)
{

  ///opening input files............

  ifstream nutrientFile;
  ifstream recipeFile;

  nutrientFile.open(nutrientFileName);
  recipeFile.open(recipeFileName);

  if(!nutrientFile || !recipeFile)

  {
    cout << "Unable to open files." << endl;
  }

  vector<Nutrient> nutrients;
  vector<Recipe> recipes;


  ///Reading nutrient file....................................


  Nutrient temp;
  getline(nutrientFile, temp.name, ';');
  nutrientFile >> temp.num_units >> temp.units >> temp.calories;
  while(nutrientFile)
  {
    temp.calories_per_unit = temp.calories/temp.num_units;
    nutrients.push_back(temp);
    getline(nutrientFile, temp.name, ';');
    nutrientFile >> temp.num_units >> temp.units >> temp.calories;

  }
    

  ///reading recipe file.....................................................

  std::string recipeTitle;
  double servings;

  recipeFile >> recipeTitle >> servings;
  Recipe myRecipe;
  recipeFile >> myRecipe.num_units >> myRecipe.units;
  getline(recipeFile, myRecipe.name);
  while(recipeFile)
  {
  recipes.push_back(myRecipe);

  ///search if recipe name is in nutrient file.....

  int pos = seqOrderedSearch(nutrients,myRecipe.name); //error
  if (pos >=0)


  recipeFile >> myRecipe.num_units >> myRecipe.units;
  getline(recipeFile, myRecipe.name);

  }


    nutrientFile.close();
    recipeFile.close();


int main (int argc, char** argv)
{

    if (argc != 3)
    {
      cerr << "Usage: " << argv[0] << " nutrientFile recipeFile" << endl;
      return -1;
    }

    computeCalories (argv[1], argv[2]);

    return 0;
}


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

#ifndef VECTORUTILS_H
#define VECTORUTILS_H

#include <vector>


// Search a vector for a given value, returning the index where
//    found or -1 if not found.

template <typename T>
int seqSearch(const std::vector<T>& list, T searchItem)
{
    int loc;

    for (loc = 0; loc < list.size(); loc++)
        if (list[loc] == searchItem)
            return loc;

    return -1;
}


// Search an ordered vector for a given value, returning the index where
//    found or -1 if not found.

template <typename T>
int seqOrderedSearch(const std::vector<T> list, T searchItem)
{
    int loc = 0;

    while (loc < list.size() && list[loc] < searchItem)
      {
       ++loc;
      }
    if (loc < list.size() && list[loc] == searchItem)
       return loc;
    else
       return -1;
}
Last edited on
if you pass a vector of Nutriant to seqOrderedSearch the second parameter has to be a Nutriant ie seqOrderedSearch(std::vector<Nutriant> , Nutriant);
you are doing seqOrderedSearch(std::vector<Nutriant> , std::string);


also your computeCalories function is missing a closing brace.
Last edited on
Topic archived. No new replies allowed.