заголовочный файл не распознает переменные из основной функции - PullRequest
0 голосов
/ 06 февраля 2020

Прежде всего, я знаю, что не стоит делать что-либо иное, чем объявить свои функции и т. Д. c ... в заголовочном файле, но мой учитель хотел, чтобы мы следовали этому формату.

Цель этой конкретной функции - сохранить пользовательский ввод в различные массивы в 'int main'.

Проблема, с которой сталкиваюсь эта функция, а также некоторые другие, заключается в том, что компилятор выдает различные ошибки, которые, я думаю, связаны с тем, что он не может распознать массивы из int main. (Только мое предположение.) на данный момент.

//header file

void getVisitorInfo(int* age[], double* hours[], string* country[]) {
  cout<<"Enter your country: ";
  getline(cin, country[vCount]);
  cout<<endl;

  cout<<"Enter your age: ";
  cin>>age[vCount];
  cout<<endl;

  cout<<"Enter the number of hours you explored: ";
  cin>>hours[vCount];
  cout<<endl;

  vCount++;
}
//main file
const int max = 100;

int main() {
  int age[max], vOldest, vYoungest, vAverage, userChoice;
  double hours[max], vShortest, vLongest, vAverage;
  string country[max];
  bool pass;

//etc...
}
//a few of many errors
test.cpp: In function ‘void getVisitorInfo(int**, double**, std::string**)’:
test.cpp:84:31: error: no matching function for call to ‘getline(std::istream&, std::string*&)’
   getline(cin, country[vCount]);
                               ^
test.cpp:84:31: note: candidates are:
In file included from /usr/include/c++/4.8.2/string:53:0,
                 from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8.2/bits/ios_base.h:41,
                 from /usr/include/c++/4.8.2/ios:42,
                 from /usr/include/c++/4.8.2/ostream:38,
                 from /usr/include/c++/4.8.2/iostream:39,
                 from test.cpp:1:
/usr/include/c++/4.8.2/bits/basic_string.tcc:1068:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
     getline(basic_istream<_CharT, _Traits>& __in,
     ^
/usr/include/c++/4.8.2/bits/basic_string.tcc:1068:5: note:   template argument deduction/substitution failed:
test.cpp:84:31: note:   mismatched types ‘std::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::string* {aka std::basic_string<char>*}’
   getline(cin, country[vCount]);
                               ^
In file included from /usr/include/c++/4.8.2/string:52:0,
                 from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8.2/bits/ios_base.h:41,
                 from /usr/include/c++/4.8.2/ios:42,
                 from /usr/include/c++/4.8.2/ostream:38,
                 from /usr/include/c++/4.8.2/iostream:39,
                 from test.cpp:1:
/usr/include/c++/4.8.2/bits/basic_string.h:2793:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
     getline(basic_istream<_CharT, _Traits>& __is,
     ^
/usr/include/c++/4.8.2/bits/basic_string.h:2793:5: note:   template argument deduction/substitution failed:
test.cpp:84:31: note:   mismatched types ‘std::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::string* {aka std::basic_string<char>*}’
   getline(cin, country[vCount]);
                               ^
test.cpp:89:6: error: no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘int*’)
   cin>>age[vCount];
      ^
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...