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.

Empfohlene Antworten

Veröffentlicht

Hi. Ich habe eine Klasse mit einem ifstream-Objekt deklariert.

Im Konstruktur soll ein ifstream-Objekt zur Initialisierung übergeben werden.

Ich erhalte dabei jedoch folgende Fehlermeldung:

error C2582: 'std::basic_ifstream<char,struct std::char_traits<char> >' : 'Operator =' ist nicht verfuegbar

.
wie kann ich das Problem mit der Initialisierung lösen?
#include <fstream>

using namespace std;


class Tupel

{

public:

  Tupel(ifstream file);   // Konstruktor

  ~Tupel();               // Destruktor


  ifstream inFile;

};
#include "lowercase.h"


Tupel::Tupel(ifstream file)

{

  inFile = file;

}


Tupel::~Tupel()

{


}

#include "lowercase.h"


Tupel::Tupel(ifstream &file)

: inFile (file)

{

}


Tupel::~Tupel()

{


}

FEHLER: error C2664: 'std::basic_ifstream<char,struct std::char_traits<char> >::basic_ifstream<char,struct std::char_traits<char> >(const char *,int)' : Konvertierung des Parameters 1 von 'class std::basic_ifstream<char,struct std::char_traits<char> >' in 'const char *' nicht moeglich

Zeig doch mal, wie du das aufrufst.

mfg

realisticer

#include <fstream>

using namespace std;


class Tupel

{

public:

  Tupel(ifstream &file);   // Konstruktor

  ~Tupel();               // Destruktor


  ifstream inFile;

private:

};
#include "lowercase.h"


Tupel::Tupel(ifstream &file)

: inFile (file)

{

}


Tupel::~Tupel()

{


}
#include <fstream>

#include "lowercase.h"

using namespace std;


int main()

{

  ifstream testFile;

  Tupel tupel1(testFile);

  return 0;

}


class Tupel
{
public:
Tupel(ifstream &file); // Konstruktor
~Tupel(); // Destruktor

ifstream inFile;
private:
};[/CODE]

Der Member muss auch eine Referenz werden. Sonst versucht der Compiler wieder, eine Kopie anzufertigen.

Übrigens: Eine using namespace-Deklaration in einer Headerdatei ist nicht so gut.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.