Re: How do you implement this Python idiom in C++

2006-07-31 Thread benben
You are heading the wrong way... There are a number of ways to implement this but the easiest I can think of is to use RTTI. To get around with counting sub-objects you can rely on virtual inheritance, which only happens at the top of the inheritance tree. Here is a simple demo: #include #in

Re: How do you implement this Python idiom in C++

2006-07-30 Thread alainpoint
Pierre Barbier de Reuille wrote: > [EMAIL PROTECTED] wrote: > > Pierre Barbier de Reuille wrote: > [...] > > > > I thank you for your response. The equivalent of your solution is > > posted hereunder: > > class cA(object): > > count=0 > > def __init__(self): > > sel

Re: How do you implement this Python idiom in C++

2006-07-30 Thread Pierre Barbier de Reuille
[EMAIL PROTECTED] wrote: > Pierre Barbier de Reuille wrote: [...] > > I thank you for your response. The equivalent of your solution is > posted hereunder: > class cA(object): > count=0 > def __init__(self): > self.__class__.count +=1 > @classmethod >

Re: How do you implement this Python idiom in C++

2006-07-30 Thread alainpoint
Pierre Barbier de Reuille wrote: > [EMAIL PROTECTED] wrote: > > Rob Williscroft wrote: > > > >> If this is more than idle curiosity I strongly suggest you post > >> a version of the python code you need to translate to C++. > > > > For the moment this is just healthy curiosity but i will still pos

Re: How do you implement this Python idiom in C++

2006-07-28 Thread Pierre Barbier de Reuille
[EMAIL PROTECTED] wrote: > Rob Williscroft wrote: > >> If this is more than idle curiosity I strongly suggest you post >> a version of the python code you need to translate to C++. > > For the moment this is just healthy curiosity but i will still post the > code i would like to see translated: >

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
Noah Roberts wrote: > What happens if you print Parent.getcount() now? You still get 2 since there is no new instance of Parent that was created. Alain -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Noah Roberts
[EMAIL PROTECTED] wrote: > Rob Williscroft wrote: > > > If this is more than idle curiosity I strongly suggest you post > > a version of the python code you need to translate to C++. > > For the moment this is just healthy curiosity but i will still post the > code i would like to see translated:

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
Rob Williscroft wrote: > If this is more than idle curiosity I strongly suggest you post > a version of the python code you need to translate to C++. For the moment this is just healthy curiosity but i will still post the code i would like to see translated: class Parent: count=0

RE: How do you implement this Python idiom in C++

2006-07-27 Thread Ames Andreas
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] g] On Behalf Of [EMAIL PROTECTED] > Sent: Thursday, July 27, 2006 5:51 PM > Subject: How do you implement this Python idiom in C++ > > I am no C++ expert but i guess there might be some

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Rob Williscroft
wrote in news:[EMAIL PROTECTED] in comp.lang.python: > #include > using namespace std; > > // A base class that provides counting > template class Counted { > static int count; > }; > > template int Counted::count = 0; > > // Curious class definitions > class CountedClass : public Counted

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Noah Roberts
[EMAIL PROTECTED] wrote: > I am no C++ expert but i guess there might be some in the Python and > C++ newsgroups. > Provide compilable code that exibits your problem. The technique is sound; you must be screwing up somehow. #include using namespace std; template class counted { static i

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Jon Clements
[EMAIL PROTECTED] wrote: > You miss the point; i want to derive a class and inherit all properties > without worrying about those implementation details. The Python code is > much cleaner in that respect. My post is about whether it is possible > to get such a clean interface in C++ I was simply

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
Jon Clements wrote: > [EMAIL PROTECTED] wrote: > > // Curious class definitions > > class CountedClass : public Counted {}; > > class CountedClass2 : public Counted {}; > > > > It apparently works but in fact it doesn't: > > If you derive from such a class, you get the count of the parent class, >

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Pierre Barbier de Reuille
[EMAIL PROTECTED] wrote: > Hello, > > I have the need to write the equivalent of Python class methods in C++. > > Chuck Allison proposes the following > (http://www.artima.com/cppsource/simple.html): > #include > using namespace std; > > // A base class that provides counting > template class C

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Jon Clements
[EMAIL PROTECTED] wrote: > // Curious class definitions > class CountedClass : public Counted {}; > class CountedClass2 : public Counted {}; > > It apparently works but in fact it doesn't: > If you derive from such a class, you get the count of the parent class, > > not of the derived class. > cla

How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
Hello, I have the need to write the equivalent of Python class methods in C++. Chuck Allison proposes the following (http://www.artima.com/cppsource/simple.html): #include using namespace std; // A base class that provides counting template class Counted { static int count; public: Counted(

How do you implement this Python idiom in C++ ?

2006-07-27 Thread alainpoint
Hello, I have the need to write the equivalent of Python class methods in C++. Chuck Allison proposes the following (http://www.artima.com/cppsource/simple.html): #include using namespace std; // A base class that provides counting template class Counted { static int count; public: Counted()