Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Kleines Problem mit Klassen und Namespaces

Empfohlene Antworten

Hallo, ich war mal wieder am cpp üben als ich mich gefragt habe wie man eigentlich gut eine eigene bibliothek erstellen kann, die hinter einem Namensraum steht, also wie der std-namespace.

nun bin ich zu folgendem code gekommen:

LError.h:



#include <string>

#include <vector>

#include <utility>


#ifndef LBib_LError 

#define LBIB_LError true



namespace LBib{

	class LError;

};


class LBib::LError{

protected:

	int error;

	::std::string description;

	::std::vector<::std::pair<::std::string,::std::string>> extra_information;

public:

	LError(void);

	LError(int error);

	LError(int error, ::std::string errordescription);

	LError(int error, ::std::string errordescription, ::std::pair<::std::string,::std::string> extra_information);

	LError(int error, ::std::string errordescription, ::std::vector<::std::pair<::std::string,::std::string>> extra_information_vector);

//etc...

LError.cpp:

#include <string>

#include <vector>

#include <utility>

#include "LError.h"


using namespace LBib;


LBib::LError::LError(void){

	this->error=false;

}

LBib::LError::LError(int error){

	this->error=error;

}

//etc

};

Das Programm klappt in der Form ohne probleme, allerdings will ich in der LError.h die includes raus bekommen, und das sollte eigentlich auch kein problem sein da ich sie ja schon in der LError.cpp einbinde, allerdings ist dies in der Paxis nicht so:
1>c:\users\laubi\documents\visual studio 2010\projects\schule\lbib\v1\lerror\lerror.h(14): error C2039: 'string': Ist kein Element von 'std'

Also meine Fragen:

Wie bekomme ich die includes raus ohne die errormeldung?

das ist sicherlich nur ein kleiner fehler, aber ich komm einfach net drauf :/

Ist das mit dem Namespace richtig so, oder macht man es in der Praxis anderst?

danke im vorraus,

Laubi

allerdings will ich in der LError.h die includes raus bekommen
Warum? Du zwingst damit jeden Benutzer deines Headers, diese Header selbst einzubinden. Du sparst nichts dadurch, und erzeugst zusätzliche Arbeit für den Benutzer deiner Klasse.

und das sollte eigentlich auch kein problem sein da ich sie ja schon in der LError.cpp einbinde
LError.cpp ist uninteressant. Der Fehler entsteht doch gar nicht beim Compilieren von LError.cpp, sondern von der .cpp-Datei, in der die Klasse benutzt werden soll.

Zusammenfassung: Lass es. Die Includedirektiven gehören da hin.

hmm, na gut

wenn es so gehört gehört es so, danke für die information

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.