Boost logo

Boost Users :

Subject: Re: [Boost-users] Emulating Python class variables in C++
From: Michael (mwpowellhtx_at_[hidden])
Date: 2015-08-02 21:16:38


On August 2, 2015 8:41:08 PM EDT, Gavin Lambert <gavinl_at_[hidden]> wrote:
>On 2/08/2015 20:05, Will Hall wrote:
>> struct A {
>> static string value;
>> };
>>
>> struct B : public A {
>> static string value;
>> };
>>
>> string A::value("A");
>> string B::value("B");
>
>While I can't answer your question directly, I can tell you that this
>is
>bad coding practice in C++. Usually it stems from a misunderstanding,
>while other times it's just a bad design.

Have you considered type traits. Don't know how that works with python though.

template<class T>
struct policy {
static const bool value = false;
};

struct policy<A> {
static const bool value = true;
};

There's an interesting tutorial here:

http://www.cantrip.org/traits.html

>> So, to summarise, any idea how to provide polymorphic Python class
>> variables in boost::python?
>
>Static/class fields cannot be polymorphic, by definition.
>
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net