namespace and data hiding

This is a discussion on namespace and data hiding within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Tux0r When the values of them are the same then the destructor is called. The destructor will ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by Tux0r View Post
    When the values of them are the same then the destructor is called. The destructor will call an event. Like, creating a chest with treasure because the enemies were defeated. I believe it makes perfect sense, and because I'm using polymorphism I have to new (afaik).
    You do not have to use new to use polymorphism.
    All you need is a pointer or reference to the base class. Thus this will work:
    Code:
    Derived a;
    Base* pa = &a;
    pa->myfunction();
    // Or
    Base& ra = a;
    ra.myfunction();
    Furthermore, using delete this is something I would not recommend.
    If you don't want to do manual deleting, then use smart pointers.
    Last edited by Elysia; 07-09-2009 at 12:37 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    Well that's a crap way to demonstrate polymorphism, since that's not polymorphic at all.

    Imagine two classes to represent the time, TwelveHourClock and TwentyFourHourClock, related through the abstract data type Time, which at minimum specifies for its children a timestamp method. One way to dump the time for all the Time types is through a polymorphic function.
    Code:
    void print (std::ostream& os, const Time& now) {
       os << "The time is " << now.timestamp() << '\n';
    }

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by whiteflags View Post
    Well that's a crap way to demonstrate polymorphism, since that's not polymorphic at all.
    It was a way to demonstrate that you don't have to use new to use polymorphism.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    But you didn't use polymorphism, so sorry if it's really my fault that you demonstrated so little.

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Alright, perhaps it was a bad example. I realize that now... I used a single class.
    Well, I edited it to use Derived and Base to demonstrate that we're talking about polymorphism.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    It will break broken usages of the facade pattern. There is nothing in the facade pattern that requires the facade to be a friend. Specifically, the facade pattern is not intended as a means of circumventing access control.
    I was not indicating this was the case.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  2. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 02:45 AM
  3. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 01:24 AM
  4. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 11:07 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21