How to refer to a method in another cpp file

I have this bit of code that I'm trying to make function, but Visual Studio is giving me error messages even before I compile (red lines):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "Converter.h"
#include "ActionRequest.h"
#include "utilities.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

//const string utilities::TextItems TEXT ("Converter.txt")
//{
//
//}


int main ()
{
    char request = 'a';
        readRequest();
}


I'll also include the header and cpp files of ActionRequest:

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
#include "ActionRequest.h"
#include <iostream>
#include <string>
using namespace std;

string actionRequestLine = " ";
void ActionRequest::readRequest()
{
    int invalidResponseCount = 3;
    int charCriteria;
    int actionRequestLength = 0;
    do
    {
        cout << "\nWhat kind of value would you like to convert?"
             << "\nEnter b (or B) for binary, d (or D) for decimal, "
             << "or q (or Q) to quit: ";
        getline(cin, actionRequestLine);
        actionRequestLength = actionRequestLine.length();
        char actionRequest = 'a';
        if (invalidResponseCount >= 1 && actionRequestLength == 1)
        {
            charCriteria = 1;
            actionRequest = actionRequestLine[0];
            switch (actionRequest)
            {
            case 'b': case 'B': case 'd': case 'D': case 'q': case 'Q':
                charCriteria = 1;
                break;
            default:
                charCriteria = 0;
                --invalidResponseCount;
                if (invalidResponseCount > 0)
                {
                    cout << "Error: Invalid response."
                         << "\nTry again. (You have " << invalidResponseCount
                         << " tries left.)\nPress Enter to continue ...";
                    cin.ignore(80,'\n');
                }
                break;
            }
        }

        if (invalidResponseCount == 0)
        {
            cout << "\nSorry but you are out of tries."
                 << "\nThe quit option will now be supplied."
                 << "\nPress Enter to continue ... ";
            cin.ignore(80,'\n');
            actionRequestLine = "q";
            break;
        }
    }while ((invalidResponseCount > 0) && (charCriteria=0)
           || (actionRequestLength != 1));
}

char ActionRequest::getRequest ()
{
    char actionRequest = actionRequestLine[0];
    return actionRequest;
}


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
//ActionRequest.h
//Lastname:Firstname:A00123456:csc122801
//Submission 10
//Decimal/Binary Conversion, Part 3 (C++ version)

/*
 * This class is complete and working according to specifications.
 */


/**
 * A class to handle user interaction when the user is choosing
 * whether to perform a decimal or binary conversion.
 */
class ActionRequest
{
public:
    void readRequest();
    /**<
     * Prompts the user for, and then reads from the user, a request
     * for action. The prompt has the following form:
     * <pre>
     * What kind of value would you like to convert?
     * Enter b (or B) for binary, d (or D) for decimal, or q (or Q) to quit:
     * </pre>
     * The input must be an uppercase or lowercase b, d or q, and
     * the user has three attempts to enter one of these values.
     * Depending on the situation when an invalid entry is
     * made, one of the following messages will be displayed:
     * <pre>
     * Error: Invalid response.
     * Try again. (You have 2 tries left.)
     * Press Enter to continue ...
     * </pre>
     * <pre>
     * Error: Invalid response.
     * Try again. (You have 1 try left.)
     * Press Enter to continue ...
     * </pre>
     * <pre>
     * Sorry, but you are out of tries.
     * The quit option will now be supplied.
     * Press Enter to continue ...
     * </pre>
     */


    char getRequest();
    /**<
     * Returns the request for action. This may be the request actually
     * entered by the user, or a program-supplied value of 'q' if the
     * user has been unable to make a valid choice in three attempts.
     */

private:
    char userRequest;

};


I've searched with trouble finding anything to resolve my problem. I'm unable to call the readRequest and getRequest functions (simply because I don't know how.) I've tried a few different ways of doing it, similar to those used in Java programming, but none worked.
You need to create an instance of the ActionRequest to call the method.

1
2
ActionRequest x;
x.readRequest();
Last edited on
Thank you, this worked perfectly.
Topic archived. No new replies allowed.