компиляция неопознанных символов C ++ для архитектуры x86_64 в векторном упражнении - PullRequest
0 голосов
/ 02 мая 2020

(обновлено с новым кодом, но та же проблема сохраняется)

Итак, выполняя домашнюю работу для моего класса C ++, она почти закончена, но просто не скомпилируется и выдает следующее сообщение об ошибке:

Undefined symbols for architecture x86_64:
  "reportNames(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, char)", referenced from:
      _main in CHomeWork11-55ac9e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

код программы выглядит следующим образом:

#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>
#include<algorithm>
using namespace std;
ifstream fin;

int getRank(vector<string> names, string choice);
void reportNames(vector<string> names, char letter);

int main ()

{
  string name;
  int counter = 0;
  string choice;
  bool on = true;
  char letter;

 vector <string> names;
 vector <string>::iterator iter;
 vector <string>::iterator iterF;

    fin.open("GirlNames.txt");  // reads in data

    getline(fin, name);

    while (!fin.fail())
    {
          names.push_back(name);
          getline(fin, name);
    }
    fin.close();

    cout << "Top Ten Baby Girl Names:" << endl;

    iter = names.begin();

    while(counter !=10)
    {
        cout << *iter << endl;
        iter++;
        counter++;
    }

    while(on)
    {
        cout << "Enter a name (press q to quit)" << endl;
        getline(cin, choice);
        if(choice == "q")
           on = false;

        else
        {
            iterF = find(names.begin(), names.end(), choice);
            if(iterF == names.end())
               cout << choice << " Is not on this list" << endl;
            else
            {
                  cout << choice << " is rank " << getRank(names, choice) << endl;
            }  
        }
    }
    sort(names.begin(), names.end());

    cout << "enter a starting letter for your name:" << endl;
    cin >> letter;
    reportNames(names, letter);
}

int getRank(vector<string> names, string choice)
{
    int rank = 1;
   for(int i = 0; i < names.size(); i++)
   {
       if(names[i] == choice)
           return rank;
        else
            rank++;
   }
   return 0; //dummy return statement for the compiler
}
void reportName(vector<string> names, char letter)
{
    for(int i = 0; i < names.size(); i++)
   {
       if(names[i].find(letter) !=string::npos)
         cout << names[i] << endl;
   }

}

Я почти уверен, что проблема связана с функцией reportName, поскольку код компилировался и выполнялся до того, как я его создал.

1 Ответ

0 голосов
/ 02 мая 2020

Сравните две строки:

void reportNames(vector<string> v, char letter);
void reportName(vector<string> names, char letter) {
...

Вы объявили функцию с одним именем, но определенную с другим.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...