我定义了一个类“Progression”并将其保存为“Progression.h”然后我创建了另一个类“ArithProgression”,它扩展了Progression类并将其保存为“ArithProgression.h”。
文件:Progression.h
#ifndef PROGRESSION_H
#define PROGRESSION_H
#include <iostream>
using namespace std;
class Progression
{
public:
Progression()
{
cur=first=0;
}
Progression(long f)
{
cur=first = f;
}
void printProgression(int n)
{
cout<<firstValue();
for(int i=0;i<=n; i++)
{
cout<<' '<<nextValue();
}
}
virtual ~Progression() {}
protected:
long first;
long cur;
virtual long firstValue()
{
cur= first;
return cur;
}
virtual long nextValue()
{
return cur++;
}
};
#endif // PROGRESSION_H
文件:ArithProgression.h
#ifndef ARITHPROGRESSION _H
#define ARITHPROGRESSION _H
#include "Progression.h"
class ArithProgression :public Progression
{
public:
ArithProgression(long i=1)
:Progression()
{
inc=i;
}
virtual ~ArithProgression () {}
protected:
long inc;
virtual long nextValue()
{
cur+=inc;
return cur;
}
private:
};
#endif // ARITHPROGRESSION _H
文件:main.cpp
#include <iostream>
#include "Progression.h"
#include "ArithProgression.h"
using namespace std;
int main()
{
Progression* p;
p= new ArithProgression();
p->printProgression(10);
delete p;
}
我收到错误:“在代码块12.11中无法将'ArithProgression *'转换为'Progression *'”
请帮助