0

I was wondering why the compiler keeps telling me

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>

using namespace std;

const int PatternSize = 8;
typedef int OperandArray[PatternSize];

// the major data structure, the BitPattern class

class BitPattern

{
public:

    // default constructor, sets all bits to zero
    BitPattern ();

    // IO routines
    void ReadBitPattern (ifstream& infile);
    void PrintBitPattern () const;

    // bit manipulation functions on one bit pattern
    // these all modify the calling object and print result internally
    void Operation_NOT ();
    void Operation_CONVERT ();
    void Operation_LSHIFT (int);
    void Operation_RSHIFT (int);

    // bit manipulation functions on two bit patterns
    // these all return an anonymous object as a result and do not print result
    const BitPattern Operation_AND (const BitPattern&) const;
    const BitPattern Operation_OR (const BitPattern&) const;
    const BitPattern Operation_ADD (const BitPattern&, bool&) const;


private:
    OperandArray bitArray;      // the array of 1s and 0s representing bits
    int BinaryExp (int);        // a helper function to calculate powers of 2
};

void ReadBitPattern (ifstream& infile)
{
    char ch;


    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            cin.get (ch);
        }
    }

    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {

        }
    }



}


void Operation_NOT ()
{       
}
void Operation_CONVERT ()
{
}
void Operation_LSHIFT (int)
{
}
void Operation_RSHIFT (int)
{
}



int main() 

{
    string operation;
    fstream getfile;


    do
    {

        cout << "Enter the input file name [no blanks!]:";
        getline(cin,operation);
        getfile.open(operation.c_str(),ios::in);


        if (!getfile.is_open())
            cout << "ERROR - file did not open." << "Please try again" << endl;


    }while(!getfile.is_open());


    while(!getfile.eof())
    {
        cin >> operation;

        if (operation == "NOT")
        {

            BitPattern ReadBitPattern;







        }

        else if (operation == "AND")
        {

        }
        else if (operation == "OR")
        {}
        else if (operation == "CONVERT")
        {}  
        else if (operation == "L_SHIFT")
        {}
        else if (operation == "R_SHIFT")
        {}

        else
        {}



    }




    return 0;
}

"Undefined symbols:
BitPattern::BitPattern(), referenced from:"

Because I thought I mentioned the Class properly.`

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by sfuo
0

If you have the function prototypes within the class and you want to define them outside, you need to define them with the proper scope.

Right now you are just declaring some functions in the global scope. To define the class's functions you need to include the scope of the class in the function definition.

For example:

void BitPattern::ReadBitPattern (ifstream& infile)
{
    char ch;

    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            cin.get (ch);
        }
    }

    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {

        }
    }
}

Notice how BitPattern:: is before the function name?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.