edit: gotcha!
forgot to add #include <string> to the header and to compile the two src together.
Good afternoon. I'm getting the error mentioned in the title when I try to pass a struct from golfers which was dinamically created.
Code:#include <iostream> #include <string> #include <cstring> #include "../Headers/golf.h" int main() { using std::cout; using std::cin; using std::strlen; using std::string; using sport::setgolf; using sport::golf; string fullname; int players, handicap; cout << "How many players are playing? "; while(!(cin >> players)) { cin.clear(); while(cin.get() != '\n') continue; cout << "Please enter how many players are playing: "; } cin.get(); golf *golfers = new golf[players]; for(int i = 0; i < players; i++) { cout << "Enter your full name: "; if(cin.get() == '\n') break; getline(cin, fullname); cout << "Enter the handicap: "; (cin >> handicap).get(); setgolf(golfers[i], fullname, handicap); } delete [] golfers; }Code:36: referência indefinida para `sport::setgolf(sport::golf&, std::string, int)'Code:#include <iostream> #include <string> #include <cstring> #include "../Headers/golf.h" namespace sport { void setgolf(golf &g, const std::string name, int hc) { g.fullname = name; g.handicap = hc; } int setgolf(golf &g) { using std::string; using std::cout; using std::cin; using std::strlen; cout << "Please enter full name: "; cin >> g.fullname; cout << "Please enter handicap: "; cin >> g.handicap; if(g.fullname.length() == 0) return 0; else return 1; } void handicap(golf &g, int hc) { g.handicap = hc; } void showgolf(const golf &g) { using std::cout; using std::endl; cout << "Your name: " << g.fullname << endl; cout << "Handicap: " << g.handicap << endl; } }Code:#ifndef GOLF_H_ #define GOLF_H_ const int LEN = 40; namespace sport { struct golf { std::string fullname; int handicap; }; // non-interactive version: // function sets golf structure to provided name, handicap // using values passed as arguments to the function void setgolf(golf & g, const std::string name, int hc); // interactive version: // function solicits name and handicap from user // and sets the members of g to the values entered // returns 1 if name is entered, 0 if name is empty string int setgolf(golf & g); // function resets handicap to new value void handicap(golf & g, int hc); // function displays contents of golf structure void showgolf(const golf & g); } #endif



1Likes
LinkBack URL
About LinkBacks



