עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

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.

מחלקות פנימיות ב-C++, כיצד?

Featured Replies

פורסם

היי,

יש לי תרגיל ליום ראשון ואני ממש תקוע עם מימוש של איטרטור ע"י מחלקה פנימית או לא(ז"א בכל דרך אחרת, ע"י מימוש אופרטורים או משהו).

אשמח להסבר על דרכים טובות למימוש איטרטור ב-C++

תודה,

אור.

פורסם

תסתכל על מימוש איטרטורים ב-STL בשביל רמזים. אתה לא חייב לעשות כל מה שהם עושים, אבל תסתכל.

http://www.gotw.ca/gotw/018.htm

http://www.gotw.ca/gotw/

תלוי בדרישות התרגיל, אבל בד"כ זה רעיון רע לממש את האיטרטורים בתור state פנימי של המחלקה עליה אתה עובר. בד"כ עדיף אובייקט איטרטור אשר שומר בעצמו את מצב האיטרציה.

לגבי מחלקות פנימיות: זה קל, אבל תזכור שב-C++ למחלקה פנימית אין גישה מיוחדת למחלקה שבתוכה היא מוגדרת. אם אתה צריך גישה כזו, תגדיר אותה כ-friend.


class Collection
{
public:

class Iterator
{
// ...
};

friend class Iterator;
};

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

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.