The class BaseSearch is the base function that I'm trying to call within the derived function (ValueSearch). The code that I have in question specifically is under ValueSearch, calling BaseSearch::Print(line, title). The compiler errors I'm getting are: I'm uncertain if I'm using inheritance correctly.
Error 1 error C2275: 'std::string' : illegal use of this type as an expression BaseSearch.cpp
BaseSearch::BaseSearch() { } BaseSearch::~BaseSearch() { } void Print(string line, string title) { char c2 = '_'; //set character to blank value; defines the header row char c = '_'; //set character to blank value; defines the searched row int numHeader = 0; //sets the value of character for the header row int numLine = 0; //sets the value of character for the searched row c2 = line[numLine]; while (true) //force while loop { c = title[numHeader]; numHeader++; //header character is set to the title array defined as the entire header string above if (c != ',') { cout << c; // couts the header until it reaches a ',' } if (c == ',' || title.size() == numHeader) // if c reaches a ',' it will print the searched row { cout << ": "; while (line.size() != numLine) { while (c2 != ',' && line.size() != numLine) { cout << line[numLine]; numLine++; if (line.size() != numLine) c2 = line[numLine]; else break; } if (line.size() != numLine) { numLine++; c2 = line[numLine]; cout << "\n"; break; } } } if (title.size() == numHeader) // if c reaches a null value, it breaks until other row is found. { cout << endl << endl; break; } } } BaseSearch.h
#ifndef BASESEARCH_H #define BASESEARCH_H #include <string> class BaseSearch { public: BaseSearch(); virtual ~BaseSearch(); virtual void Print(string, string); }; Value Search.cpp
ValueSearch::ValueSearch() { string input; } ValueSearch::~ValueSearch() { //dtor } double ValueSearch::getInput() { cout << endl << "Enter the name of the company you would like to search for: "; cin >> input; return input; } void ValueSearch::ValueSearchFunc(int c, int x) { column = c; // cout << "Enter the name of the company you would like to search for: "; // getline(cin, input); string line; ifstream fs("Stock Database.csv"); string title; getline(fs, title); while (!fs.eof()) { getline(fs, line); string companyname = ""; //start as blank, then append string a; int commacount = 0; //how many commas have we passed int ChrCount = 0; //counter for which character in the line we are looking at while (line != "\0") //while the line does not equal to null value. { double price; price = 0; a = line[ChrCount]; //convert char c to a string (a) so that we can append ChrCount++; if (a == ",") { commacount++; //increases the comma count as a encounters a comma each time. } else if (commacount == column && (a != "N" && a != "/" && a != "A")) //if comma count is equal to the set column, it will append the string company name. { while (a != ",") { if (a != ",") { companyname.append(a); a = line[ChrCount]; ChrCount++; } }ChrCount--; price = stod(companyname); } else if (commacount > column) // if the comma count is any value larger than the column, breaks out of loop. { break; } if (input == 0) { break; } if (x == 1){ if (price >= input && price != 0) // if the appended company name is equal to the search input entered, it will cout the entire row. BaseSearch::Print(line, title); } if (x == 2) { if (price <= input && price != 0) // if the appended company name is equal to the search input entered, it will cout the entire row. BaseSearch::Print(line, title); }//end if } } } ValueSearch.h
#ifndef VALUESEARCH_H #define VALUESEARCH_H #include <string> #include "BaseSearch.h" class ValueSearch : public BaseSearch { public: ValueSearch(); ~ValueSearch(); double getInput(); void ValueSearchFunc(int c, int x); void Print(string,string) {BaseSearch::Print(string,string);} protected: private: double input; int column; }; #endif