Mistaking vector function for a member function?

Hello I've been working on my coursework for the whole day but I keep getting this one specific error and I have no idea how to fix it....

My project is about Templates, Abstract Classes, Virtual Functions etc. So this is my code:

  #include <iostream>
#include <string>
#include <vector>

using namespace std;

template<class CellType>

class CAbstractCell
{
protected:

    int m_iRow;
    int m_iColumn;
    CellType m_oCellType;

public:

    CAbstractCell()
    {
        m_iRow = 0;
        m_iColumn = 0;
    }

    CAbstractCell(const int& iRow, const int& iColumn, CellType& oCellType)
    {
        m_iRow = iRow;
        m_iColumn = iColumn;
        m_oCellType = oCellType;
    }


    virtual void SetValue(const CellType& oCellType) = 0;
    virtual CellType GetValue()const = 0;

};


template<class CellType>
class CCellDescr : CAbstractCell<CellType>
{

public:

    CCellDescr()
    {

    }

    CCellDescr(const int& iRow, const int& iColumn, CellType& oCellType) :
        CAbstractCell<CellType>(iRow, iColumn, oCellType)
    {
        m_iRow = iRow;
        m_iColumn = iColumn;
        m_oCellType = oCellType;
    }

    CCellDescr(const CAbstractCell& oSourceValue) :
    CAbstractCell<CellType>(oSourceValue)
    {
        m_iRow = oSourceValue.m_iRow;
        m_iColumn = oSourceValue.m_iColumn;
        m_oCellType = oSourceValue.m_oCellType;
    }

    const int GetRow() const
    {
        return m_iRow;
    }

    const int GetColumn() const
    {
        return m_iColumn;
    }

    virtual void SetValue(const CellType& oCellType)
    {
        m_oCellType = oCellType;
    }

    virtual CellType GetValue()const
    {
        return m_oCellType;
    }

    ostream& operator<<(ostream& toStream)
    {
        toStream << "Rows: " << m_iRow <<
            "\n Columns: " << m_iRows << 
            "\n Cell Value: " << m_oCellValue << endl;
    }

};


template<class CellType>
class CColumn : CCellDescr<CellType>
{

private:

    string m_strColumnName;

    vector<CCellDescr<CellType>> m_oArray;

public:

    static const int m_iCounter = 0;

    CColumn()
    {
        m_strColumnName = "";
    }

    CColumn(const string& strColumnName)
    {
        m_strColumnName = strColumnName;
    }

    void SetRowValue(const int& iRow, const CellType& oCellType)
    {
        //m_oArray.resize((m_oArray.size()+1)); // Resizing the Vector

        CCellValue<CellType> oCellValue = m_oArray[iRow];
        oCellValue.SetCellValue(oCellType);
    }

    void SetColumnName(const string& strColumnName)
    {
        m_strColumnName = strColumnName;
    }

    const string GetColumnName() const
    {
        return m_strColumnName;
    }

    const int GetArrayLength() const
    {
        return m_oArray.size();
    }

    const CCellDescr<CellType> GetRowValue(const int& i) const
    {
        return m_oArray[i].pop_back();
    }

    // need to be Fixed
    static int iConsecutiveNumbersGeneratror(int iFirstNumber, int iLastNumber)
    {
        if (iFirstNumber >= iLastNumber)
        {

            if (iFirstNumber > (iLastNumber))
            {
                cout << iFirstNumber << endl;
                iFirstNumber--;
                return iConsecutiveNumbersGeneratror(iFirstNumber, iLastNumber);
            }
            if (iFirstNumber == iLastNumber)
            {
                cout << iLastNumber << endl;
            }

            return iFirstNumber;
        }

        if (iFirstNumber <= iLastNumber)
        {

            if (iFirstNumber < (iLastNumber))
            {
                cout << iFirstNumber << endl;
                iFirstNumber++;
                return iConsecutiveNumbersGeneratror(iFirstNumber, iLastNumber);
            }
            if (iFirstNumber == iLastNumber)
            {
                cout << iLastNumber << endl;
            }

            return iFirstNumber;
        }

        return 0;
    }



};


void main()
{

    CCellDescr<string> c;
    CColumn<string> oColumn1;
    CColumn<int> oColumn2;

    int N = 4;


    oColumn1.SetColumnName("Column1");

    for (int i = 0; i < N; i++)
    {
        oColumn1.SetRowValue(i, "testing");
    }

    oColumn2.SetColumnName("Column2");

    for (int i = 0; i < N; i++)
    {
        oColumn2.SetRowValue(i, rand() % 30);
    }

    cout << oColumn1.GetColumnName() << endl;
    cout << oColumn1.GetArrayLength() << endl;

    cout << oColumn2.GetColumnName() << endl;
    cout << oColumn2.GetArrayLength() << endl;

    for (int i = 0; i < oColumn2.GetArrayLength(); i++)
    {
        cout << oColumn2.GetRowValue(i).GetValue() << endl;
    }

    oColumn2.iConsecutiveNumbersGeneratror(0, 10);

    system("pause");
}

And i keep getting an error at:

const CCellDescr<CellType> GetRowValue(const int& i) const
{
    return m_oArray[i].pop_back();
}

that says:

Error C2039 'pop_back': is not a member of 'CCellDescr' CourseWork_OOP d:\my documents\visual studio 2015\projects\coursework_oop\coursework_oop\source.cpp 145

1 answer

  • answered 2018-04-14 15:41 Jfc lol

    nvm i figured out the mistake xD i guess i didn't have to use pop_back at all and just return the vector as it is; and also i found 2 more mistakes where i forgot to change the name of my class and function:

    from:

    CCellValue<CellType> oCellValue = m_oArray[iRow];
    oCellValue.SetCellValue(oCellType);
    

    to:

    CCellDescr<CellType> oCellValue = m_oArray[iRow];
    oCellValue.SetValue(oCellType);