Sep 11, 2014 at 4:30pm UTC
So Im trying to declare a object "Konto" on the Bank class, but the compiler complains:" Bank.h|11|error: 'Konto' was not declared in this scope|"
What have I missed? Kinda frustrating atm.
Main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "Konto.h"
#include "Bank.h"
#include <iostream>
using namespace std;
int main()
{
Konto testKonto;
Bank testBank;
return 0;
}
Konto.cpp
1 2 3 4 5 6 7 8 9 10 11
#include "Bank.h"
#include <iostream>
using namespace std;
Konto::Konto()
: ranta(0.3)
{
//ctor
}
Konto.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#ifndef KONTO_H
#define KONTO_H
#include "Bank.h"
#include <string>
using namespace std;
class Konto
{
public :
Konto();
void skrivUt();
double geNummer();
double rantaUt();
private :
double kontoNr, saldo;
string kontoAgare;
const float ranta;
};
Bank.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "Konto.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
Bank::Bank()
{
//ctor
}
Bank::nyttKonto(string namn)
{
Konto nyttKonto;
vector<kontoLista>.push_back(nyttKonto);
}
Bank.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef BANK_H
#define BANK_H
#include "Konto.h"
#include <vector>
#include <string>
using namespace std;
class Bank
{
public :
Bank();
Konto nyttKonto; // This is the one that the compiler shouts about!
vector<Konto> kontoLista;
void skrivKontoLista();
void nyttKonto(string namn);
double ranteUtbetalning();
void sokKonto();
private :
double antalKonton;
};
Last edited on Sep 11, 2014 at 4:32pm UTC
Sep 11, 2014 at 4:46pm UTC
Looks like you have a circular dependency. Bank.h includes Konto.h and Konto.h includes Bank.h.
It looks like Konto.h doesn't need to include Bank.h so if you remove that include it will hopefully work.
Last edited on Sep 11, 2014 at 4:46pm UTC
Sep 11, 2014 at 6:46pm UTC
Thanks alot Peter! That fixed it!
All the hour's I spent on that simple fix..