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
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
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
[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
[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
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;
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;
[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
[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
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
[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
[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
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 :
-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
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
[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
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
17 matches
Mail list logo