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.

Probleme mit einer Deklaration in einer Klasse

Empfohlene Antworten

Veröffentlicht

hallo zusammen.

wir nehmen grad das thema klassenaufbau durch. in meiner klasse habe ich für ein auto den hersteller und den typ deklarariert den der benutzer per main eingeben soll.

das problem welches ich nun aber habe weiß ich nicht zu lösen,so blöd wie es sich auch anhört.

erstmal der code


class Auto

{

	private:

			char Hersteller[20];

			char Typ[20];

	public:

			void setHersteller (char *hersteller);

			void setTyp (char *typ);


			char *getHersteller ();

			char *getTyp ();

};

void Auto::setHersteller (char *hersteller)

{

	strcpy_s(Hersteller,hersteller);

}


void setTyp (char *typ)

{

	strcpy_s(Typ,typ);

}


char* Auto::getHersteller ()

{

	return Hersteller;

}


char *Auto::getTyp ()

{

	return Typ;

}


int _tmain(int argc, _TCHAR* argv[])

{

	Auto Modell;

	char hersteller[20], typ [20];


	cout<<"Hersteller eingeben"<<endl;

	cin>>hersteller;

	Modell.setHersteller(hersteller);


	cout<<"Typ eingeben"<<endl;

	cin>>typ;

	Modell.setTyp(typ);


	cout<<endl;

	cout<<"Hersteller: "<<Modell.getHersteller()<<endl;

	cout<<"Typ: "<<Modell.getTyp()<<endl;



	return 0;

}

in meiner methode 'void setTyp (char *typ)'sagt der compiler das 'Typ'

ein nichtdeklarierter bezeichner ist.

sieht hier jemand nen fehler den ich übersehe? ich sehe kein unterschied zur deklaration vom hersteller.

grüße

voldemort

in meiner methode 'void setTyp (char *typ)'sagt der compiler das 'Typ'

ein nichtdeklarierter bezeichner ist.

Und damit hat er recht. Du hast da eine bisher nicht deklarierte freie Funktion definiert, die nichts mit deiner Klasse zu tun hat. Sonst würde sie ja Auto::setTyp heißen ;)

Ich rate dir übrigens dringend, an Stelle von char-Arrays std::string zu benutzen. Macht vieles einfacher.

na brat mir einer nen storch und die beine recht knusprig ;)

danke für die hilfe.

werd mir das mit dem std::string mal anschauen.

grüße

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.