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.

Klassen in C++

Empfohlene Antworten

Veröffentlicht

hi leute,

habe gerade mit klassen in c++ angefangen und hab da so ein

problem mit den zugriffen. werte die ich einlese, kann ich nicht

ausgeben.

dank im vorraus.

hier der quellcode

#include <stdio.h>

#include <iostream.h>

#include <string.h>

class speicher

{

private:

int velocity;

char model[20];

char size[20];

public:

void eins (int neu)

{velocity=neu;}

void zwei (char neu1[20])

{model[20]=neu1[20];}

void drei (char neu2[20])

{size[20]=neu2[20];}

};

void main()

{

int a;

char b[20];

char c[20];

printf("Geschwindigkeit: ");

scanf("%d", &a);

fflush(stdin);

printf("Marke: ");

scanf("%s", &b[0]);

fflush(stdin);

printf("Groesse: ");

scanf("%s", &c[0]);

fflush(stdin);

speicher family;

family.eins(a);

family.zwei(B);

family.drei©;

printf("%d\n", family);

printf("%s\n", family); // hier liegt das Problem vor! Hab kein Plan

printf("%s\n", family); //wie ich auf die weiteren Werte zugreifen

//kann.

}

Hi,

Auf die Werte in deiner Klasse kannst du nicht direkt zugreifen da du sie als private

deklariert hast. Um von außerhalb der Klasse darauf zuzugreifen mußt du eine

Methode in deiner Klasse deklarieren die die Variable zurückgibt. Ungefähr so:


int GetVelocity()
{
return Velocity;
}
[/PHP]

Außerdem kannst du einem Array nicht mit = ein anderes Array zuweisen, sondern du

mußt die Funktion strcpy benutzen.

Gruß

Guybrush

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.