You are passing a class name (which is just a kind of template) while you should pass an object to the Add method.
EntryLevel *lvl=new EntryLevel(15.0,true); entryLevels.Add(lvl);
- Amir Yacoby #: You are passing a class name (which is just a kind of template) while you should pass an object to the Add method.
It's not a “Kind of template.” That is calling the EntryLevel constructor. void EntryLevel(double p, bool d)
- WorthyVII: I am trying to use CArrayList with a custom class, but when I try to Add to it, it doesn't seem to know which function to use - is this a bug in the platform? How can I specify?
How To Ask Questions The Smart Way. (2004)
Don't rush to claim that you have found a bug.
Questions Not To Ask
My program doesn't work. I think system facility X is broken.It is almost always your code.
entryLevels is a list of pointers.
You are not passing a pointer, you are passing the object.CArrayList<EntryLevel*> entryLevels; entryLevels.Add( EntryLevel(15.0, true));
Pass the pointer. entryLevels.Add(new EntryLevel(15.0, true));
No, not correct.
The code of OP is not calling the construcor - it just passes the class name.
EntryLevel(15.0,true) ==> This is the ops code - is not calling constructor new EntryLevel(15.0,true) ==> This calls the constructor
And a class is a kind of template.
Hope I'm not in the block list now.
Shana Tova
entryLevels is a list of pointers.
You are not passing a pointer, you are passing the object.Pass the pointer.
He is not "passing the object" - he is passing a class name with parameters - which is wrong. What I gave is passing the object explicitly, what you gave at 3 is the same, unexplicitely (and only if the OP doesn't need the pointer).
Of course I preffered not to show that as It is clear that OP does not know those nuances so best to write as I wrote and not show how smart I am..
EntryLevel(15.0,true) ==> This is the ops code - is not calling constructor new EntryLevel(15.0,true) ==> This calls the constructor
Wrong! You can not create an object without calling its constructor. Change the constructor (e.g. add a third argument) and both lines no longer compile.
Wrong! You can not create an object without calling its constructor. Change the constructor (e.g. add a third argument) and both lines no longer compile.
Of course, what's new here? oops.. double meaning.
The parameter to Add is an object which is created with 'new' - same in my example and yours.
And to clarify for the OP
The constructor is like a static method (class method), you can call it even when there's not an object yet (actually, that's what it's for - creating an object).
But, OO languages usually use the 'new' for calling a constructor as a way to make sure you understand that this call returns an object of the class template(template - just using it as a means to explain to NOOB what is a class, because there's something else called 'class template' not meant here). Not using the 'new' is just wrong syntax as the outcome of constructor by definition must be a new object.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to use CArrayList with a custom class, but when I try to Add to it, it doesn't seem to know which function to use - is this a bug in the platform? How can I specify?