If I type g++ main.cpp, I get the error:
/tmp/ccalbYhC.o(.text+0x160): In function `main':
: undefined reference to `CBigInteger::CBigInteger()'
/tmp/ccalbYhC.o(.text+0x389): In function `main':
: undefined reference to `CBigInteger::CBigInteger(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccalbYhC.o(.text+0x43d): In function `main':
: undefined reference to `CBigInteger::display()'
collect2: ld returned 1 exit status

I get no errors by using
g++ -c main.cpp
g++ -c CBigInteger.cpp
g++ main.o CBigInteger.o
but my grader will compile just using g++ main.cpp

What am I missing?
Here is my code:

main.cpp

#include "CBigInteger.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

int main(void)
{
        string filename;
        CBigInteger cls[2];
        cout<<"Enter name of input file: ";
        getline(cin, filename);
        ifstream fin(filename.c_str());
        if(!fin)
        {
                cout<<"File cannot be opened\n";
                return 0;
        }
        string lineOfData;
        stringstream ss;
        CBigInteger* p;
        char tempDigit;
        getline(fin, lineOfData);
        int count = 0;
        while(!fin.eof())
        {
                if ((count == 0) || (count == 1))
                {
                        p = new CBigInteger(ss, lineOfData);
                        cls[count] = *p;
                        cls[count].display();
                        delete p;
                        count++;
                }
                else
                {
                        //read char and do case structure for what operation to do
                        count = 0;
                }
                ss.clear();
                getline(fin, lineOfData);
        }
        fin.close(); //close file
        //iterate over cls
return 0;
}

CBigInteger.h

#ifndef CBIGINTEGER_H
#define CBIGINTEGER_H
#include <list>
#include <string>
#include <sstream>
using namespace std;

class CBigInteger
{
private:
        list<char> num;
        list<char>::iterator it;
public:
        CBigInteger(void);
        CBigInteger(stringstream&, string);
        void display(void);
        void setNum(list<char>&);
        list<char>& getNum(void);
};
#endif

CBigInteger.cpp

#include "CBigInteger.h"
#include <iostream>
#include <sstream>
#include <cstddef>
using namespace std;

CBigInteger::CBigInteger(void){}

CBigInteger::CBigInteger(stringstream &ss, string lineOfData)
{
        char tempDigit;
        ss<<lineOfData;
        ss>>tempDigit;
        while(ss)
        {
                num.push_back(tempDigit);
                setNum(num);
                ss>>tempDigit;
        }
}

list<char>& CBigInteger::getNum(void)
{
        return num;
}

void CBigInteger::setNum(list<char> &newnum)
{
        num = newnum;
}

void CBigInteger::display(void)
{
        char temp;
        if (num.empty())
                cout<<"Number cannot be displayed.\n\n";
        else
        {
                it = num.begin();
                while(it!=num.end())
                {
                        temp = *it;
                        cout<<temp;
                        it++;
                }
                cout<<"\n";
        }
}

when you type g++ main.cpp the compiler is going to compile main.cpp then attempt to link the executable. But it can't because it doesn't know anything about CBigInteger.cpp

You can solve the problem by typing this: g++ main.cpp CBigInteger.cpp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.