你好我一整天都在做我的课程,但我一直有这个特定的错误,我不知道如何解决它....
我的项目是关于模板,抽象类,虚拟功能等。 所以这是我的代码:
#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");
}
我一直在收到错误:
const CCellDescr<CellType> GetRowValue(const int& i) const
{
return m_oArray[i].pop_back();
}
说:
错误C2039'pop_back':不是'CCellDescr'的成员CourseWork_OOP d:\ my documents \ visual studio 2015 \ projects \ coursework_oop \ coursework_oop \ source.cpp 145
答案 0 :(得分:0)
nvm我想出了错误xD我想我根本不必使用pop_back而只是按原样返回向量;而且我还发现了2个错误,我忘了更改班级和职能的名称:
从:
CCellValue<CellType> oCellValue = m_oArray[iRow];
oCellValue.SetCellValue(oCellType);
为:
CCellDescr<CellType> oCellValue = m_oArray[iRow];
oCellValue.SetValue(oCellType);