I am fairly new to c++ (java background) and I'm trying to access a member of a class I have created but I keep getting an error message when trying to call a member of a class, it's saying that the variable is not a member of the class.
Any ideas why this is happening? I've looked at so many other examples of people with this problem, but none of them have helped me find out why
Main.cpp
#include "stdafx.h"
#include "Adressbuch.h"
#include "Kontakt.h"
#include <iostream>
#include <sstream>
using namespace std;
Adressbuch hinzufügen(Adressbuch buch);
Adressbuch löschen(Adressbuch buch);
void auflisten(Adressbuch buch);
int main()
{
bool end = true;
Adressbuch buch;
while (end) {
cout << "Bitte geben sie ein Aktion ein: (hinzufügen(h)/löschen(l)/beenden(b)/auflisten(a))"
<< endl << "zur Zeit gibt es " << buch.adress_buch.size() << " Kontakte" << endl;
if (cin >> "h") buch = hinzufügen(buch);
else if (cin >> "l") buch = löschen(buch);
else if (cin >> "a") auflisten(buch);
else if (cin >> "b") end = true;
else cout << "Error. Ungultig Eingabe." << endl;
}
return 0;
Adressbuch.h
#include "Kontakt.h"
#include <list>
class Adressbuch{
public:
Adressbuch();
~Adressbuch();
void hinzufügen(Kontakt k);
void löschen(Kontakt k);
list<Kontakt> Adressbuch::adress_buch;
};
Adressbuch.cpp
#include "Adressbuch.h"
#include "Kontakt.h"
#include <list>
using namespace std;
Adressbuch::Adressbuch(){
adress_buch;
}
Adressbuch::~Adressbuch(){
}
void Adressbuch::hinzufügen(Kontakt k){
adress_buch.push_back(k);
}
void Adressbuch::löschen(Kontakt k) {
adress_buch.remove(k);
}
The member that I am having trouble with, is the list adress_buch. Anytime I try to call it, it says its not a member, even though it is defined in the header class?
Error message on line 19 of main()
Severity Code Description Project File Line Suppression State
Error C2039 'adress_buch': is not a member of 'Adressbuch'
ConsoleApplication5 c:\users\gregs\documents\visual studio
2015\projects\consoleapplication5\consoleapplication5\consoleapplication5.cpp 19