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

2006-07-31 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): self.__class__.count

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

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 post the code i

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 def

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: class

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 iostream using namespace std; // A base class that provides counting templateclass T class Counted { static int count;

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 iostream using namespace std; // A base class that provides counting templateclass T class Counted { static int count;

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 CountedCountedClass {}; class CountedClass2 : public CountedCountedClass2 {}; 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

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 iostream using namespace std; // A base class that provides counting templateclass T

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 CountedCountedClass {}; class CountedClass2 : public CountedCountedClass2 {}; It apparently works but in fact it doesn't: If you derive from such a class, you get the count of the

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 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 iostream using namespace std; template typename T class

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 iostream using namespace std; // A base class that provides counting templateclass T class Counted { static int count; }; templateclass T int CountedT::count = 0; // Curious class definitions class CountedClass :

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 in the Python and C++ newsgroups

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 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: class

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