Reputation: 69
What's wrong in this code ? I get [Error] expected class-name before '{' token (Pralka.h line 14 )
i know there are lots of similar questions here. I've googled too but I can't get over it. So I would like to show you my code..
I wrote this very simple code to train myself on inheritance and virtual functions..
main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include "AGD.h"
using namespace std;
int main() {
Pralka p1("polar", 1250);
AGD *A;
A = &p1;
}
AGD.h:
#ifndef AGD_H
#define AGD_H
#include <iostream>
#include "Pralka.h"
class AGD {
private:
static int liczba_sprzetow;
public:
AGD(){
liczba_sprzetow++;
}
~AGD(){
liczba_sprzetow--;
}
static int get_liczba_sprzetow() {
return liczba_sprzetow;
}
virtual double get_cena() {
}
};
#endif
Pralka.h:
#ifndef PRALKA_H
#define PRALKA_H
#include <iostream>
#include <string>
using namespace std;
class Pralka : public AGD
{
private:
string marka;
double cena;
public:
Pralka(string m, double c): marka(m), cena(c){
}
Pralka(){
}
~Pralka(){
}
string get_marka() const{
return marka;
}
double get_cena() const{
return cena;
}
Pralka& operator=(const Pralka& Q){
marka=Q.marka;
cena=Q.cena;
}
};
#endif
I get also [Error] cannot convert 'Pralka*' to 'AGD*' in assignment but why? I don't understand (main.cpp line 29).
Upvotes: 0
Views: 256
Reputation: 5766
AGD.h
is including Pralka.h
, but it should be the other way round (Pralka.h
should be including AGD.h
).
The reason is that Pralka
needs to see the AGD
declaration to inherit from it. AGD
doesn't need to see the Pralka
declaration.
Upvotes: 5