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

liebe leute

ich hab eine template klasse des typs struktur<T>.

im main programm hab ich nun eine

set<struktur<string>, greater<struktur<string> > setW erzeugt und möchte die einer methode der template klasse übergeben. ich krieg das einfach nicht hin, was muss ich denn für eine signatur bei der funktion verwenden?

funktion(set<struktur<T>, greater<struktur<T> >&) funktioniert jedenfalls nicht :confused:

kann mir jemand rat geben? wäre sehr, sehr dankbar!

nova

Entweder nimmst Du die "ausformulierte Version":

typ funktion(set<struktur<string>, greater<struktur<string> >&);

Oder du musst, wenn du unterschiedliche Templateargumente verwenden willst, die Funktion auch als Template deklarieren:

template<class T> typ funktion(set<struktur<T>, greater<struktur<T> >&);

danke für die antwort!

dummerweise, hab ich jetzt ein anderes problem: ich möchte die set direkt nach jeder eingabe mit setW.insert(wert) auffüllen.

wenn ich aber die set ausgeben will, mit einer schleife

for(j=setW.begin(); j != setW.end(); j++)

print(*j)

wird immer nur der erste wert ausgegeben.

:confused: :confused: wieso das? kann man mit insert, nicht gleich die daten in der richtigen reihenfolge einfügen lassen?

Ich würde setW.end() einmal vorher bestimmen, und nicht j++, sondern ++j schreiben, aber das sollte sich nur auf die Performance, nicht auf das Ergebnis auswirken.

Wenn das der ganze Code der Schleife ist, und nur ein Element ausgegeben wird, dann hat das Set nur ein Element. Wahrscheinlich liegt der Fehler an einer anderen Stelle. Zeig doch bitte mal den Minimalcode, mit dem man den Fehler reproduzieren kann.

Das hier funktioniert:

#include <iostream>
#include <string>
#include <set>
using namespace std;

template<class T>
void foo( set<T>& s )
{
set<T>::const_iterator i = s.begin(), iend = s.end();
for( ;i != iend; ++i )
cout << *i << endl;;
}

int main()
{
set<string> s;
s.insert("blubb");
s.insert("bla");
foo(s);
}
[/CODE]

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.