2012-02-26 12 views
5

मैं कक्षा से स्थिर क्षेत्रों निर्यात करने के लिए कोशिश कर रहा हूँ:luabind और स्थिर क्षेत्रों

class Foo 
{ 
    const static int Var; 
}; 

// luabind module: 
.def_readonly("Var", &Foo::Var); 
// I've also tried 
.def_readonly("Var", Foo::Var); 
error: no matching function for call to ‘luabind::class_<Foo>::def_readonly(const char [6], const Foo&)’ 
note: template<class C, class D> luabind::class_& luabind::class_::def_readwrite(const char*, D C::*) 

क्या मैं याद किया है?

उत्तर

3

As clearly stated in the documentation, स्थिर कार्यों (अन्य चीजों के साथ) सदस्यों के रूप में नहीं जोड़ा जा सकता है। उन्हें एक विशेष .scope निर्माण में स्कॉप्ड किया जाना है।

class_<foo>("foo") 
    .def(constructor<>()) 
    .scope 
    [ 
     class_<inner>("nested"), 
     def("f", &f) 
    ]; 

मैं नहीं पता है अगर def के गैर सदस्य समारोह संस्करण चर के लिए readonly संस्करणों है, लेकिन यह हो सकता है। यदि ऐसा नहीं होता है, तो आपको इसे एक फ़ंक्शन के रूप में बेनकाब करना होगा जो मान देता है।

+0

ठीक है, धन्यवाद। मुझे याद आया कि यह न केवल स्थिर कार्यों के लिए है। – Ockonal

संबंधित मुद्दे