PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > How to define multiple initialize methods in embedded mode?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to define multiple initialize methods in embedded mode?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/03/2008, 09h20   #1
Chirag Mistry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to define multiple initialize methods in embedded mode?

Hi

I have embedded Ruby in C++ application. I want to define multiple
"initialize" method in the Ruby class. Please let me know which sequence
of call is required to implement it? I tried following sequence of call
but it is not working. It only defines last "initialize" method.

Code snapshot:
####################
// Define class under “MyModule†module
mMyClass = rb_define_class_under(mMyModule, "MyClass", rb_cObject);
rb_gc_register_address(&mMyClass);
// Define “initialize†method without any parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(defaultInitialize) , 0);
// Define “initialize†method with one parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(initialize1), 1);
####################

In above code, it is only calling “initialize1†which accepts single
parameter. Please let me know what is wrong in above code snapshot and
correct it so I can define more than one “initialize†method in same
class.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 10/03/2008, 12h31   #2
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define multiple initialize methods in embedded mode?

On 3/10/08, Chirag Mistry <chirag80bece@gmail.com> wrote:
> Hi
>
> I have embedded Ruby in C++ application. I want to define multiple
> "initialize" method in the Ruby class. Please let me know which sequence
> of call is required to implement it? I tried following sequence of call
> but it is not working. It only defines last "initialize" method.
>
> Code snapshot:
> ####################
> // Define class under "MyModule" module
> mMyClass = rb_define_class_under(mMyModule, "MyClass", rb_cObject);
> rb_gc_register_address(&mMyClass);
> // Define "initialize" method without any parameter
> rb_define_method(mMyClass, "initialize",
> reinterpret_cast<VALUE(*)(...)>(defaultInitialize) , 0);
> // Define "initialize" method with one parameter
> rb_define_method(mMyClass, "initialize",
> reinterpret_cast<VALUE(*)(...)>(initialize1), 1);
> ####################
>
> In above code, it is only calling "initialize1" which accepts single
> parameter. Please let me know what is wrong in above code snapshot and
> correct it so I can define more than one "initialize" method in same
> class.


It can't be done. Ruby doesn't have the concept of overloading.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08039 seconds with 10 queries