информационная безопасность
без паники и всерьез
 подробно о проектеRambler's Top100
Атака на InternetГде водятся OGRыСетевые кракеры и правда о деле Левина
BugTraq.Ru
Русский BugTraq
 Анализ криптографических сетевых... 
 Модель надежности двухузлового... 
 Специальные марковские модели надежности... 
 Бэкдор в xz/liblzma, предназначенный... 
 Три миллиона электронных замков... 
 Doom на газонокосилках 
главная обзор RSN блог библиотека закон бред форум dnet о проекте
bugtraq.ru / форум / programming
Имя Пароль
ФОРУМ
все доски
FAQ
IRC
новые сообщения
site updates
guestbook
beginners
sysadmin
programming
operating systems
theory
web building
software
hardware
networking
law
hacking
gadgets
job
dnet
humor
miscellaneous
scrap
регистрация





Легенда:
  новое сообщение
  закрытая нитка
  новое сообщение
  в закрытой нитке
  старое сообщение
  • Напоминаю, что масса вопросов по функционированию форума снимается после прочтения его описания.
  • Новичкам также крайне полезно ознакомиться с данным документом.
[C++] Final words 02.08.01 01:25  Число просмотров: 874
Автор: kabanchik Статус: Незарегистрированный пользователь
<"чистая" ссылка>
let's do another exersise :

> #include <iostream>
> using namespace std;
> 
> class Base {
> public:
>   virtual int f() const { return 1; }
> };
> 
> class Derived : public Base {
> public:
>   int f() const { return 2; }
     void foo()
     {
          this->~Derived();
          new (this)Base;
          f(); // is here late or early binding ???
          // according your words, here must by early binding. right? look at the results
     }
> };
> 
> int main() {
>   Derived d;
>   Base* b1 = &d;
>   Base& b2 = d;
>   Base b3;
>   // Late binding for both:
>   cout << "b1->f() = " << b1->f()
> << endl;
>   cout << "b2.f() = " << b2.f() << endl;
>   // Early binding (probably):
^^^^^^^^^^^^^ good words. you can only suppose, but I gues you are not sure.
>   cout << "b3.f() = " << b3.f() << endl;
> } ///:~ 

---

> In b1–>f( ) and b2.f( ) addresses are used, which means
> the information is incomplete: b1 and b2 can represent the
> address of a Base or something derived from Base, so the
> virtual mechanism must be used. When calling b3.f( )
> there’s no ambiguity. The compiler knows the exact type and
> that it’s an object, so it can’t possibly be an object
> derived from Base — it’s exactly a Base. Thus early binding
> is probably used. However, if the compiler doesn’t want to
> work so hard, it can still use late binding and the same
> behavior will occur.
Very logic, but not completed. as i said we can only suppose. looking at the results you are right, but the question was is it correct ?

>
> P.S. tema zakryta.
З.Ы. давно пора.
<programming> Поиск 






Rambler's Top100
Рейтинг@Mail.ru


  Copyright © 2001-2024 Dmitry Leonov   Page build time: 0 s   Design: Vadim Derkach