quest
uh..how do you extend ur class in c++?
i know in java u just say whtever "class name" extends "class name"
how do u do that in c++?
thanxs
matt
[175 byte] By [
m_prog] at [2007-11-18 13:40:09]

# 1 Re: quest
In the book I got in hand right now, "extend" keyword in java is similar to : in C++ which says it is for inheritance...
Is that what you wanted to know ??
If so, class A{..........//declare a base class};
class B:public A{.....}//B is then a derived class from AIf not, state what you wanted to know again, I hope people will help you then...
Regards,
-Nina
# 2 Re: quest
ok example::
class A{
//code
};
class B->here is where i get stuck.
i have a class C which is extention of class B.
but i also have to inherit class A because it uses some of its elements.
so do i say:
class B:class A: class C
i dont understand
:confused:
also:
i dont understand wht is wrong w/this code:
//part of enumeration code
where::
Object ** A;
int size;
int count = 0;
range(){return size;}
Object* Vector::nextElement(){
if(count == A->range()) //this is not right
cerr << "Element doesn't exit" << endl;
int m = count+1;
return ((*A)[m];//this is not right either
}
:mad:
# 3 Re: quest
class A
{
// ...
};
class B : public A // B inherits from ("extends") A
{
// ...
};
class C : public B // C inherits from B (and, hence, from A)
{
// ...
};
# 4 Re: quest
ok i understand the class extends thing. is abstract a similar notion?
i still needed help on the syntax error thing
i dont understand wht is wrong w/this code:
//part of enumeration code
where->
Object ** A;
int size;
int count = 0;
range(){return size;}
Object* Vector::nextElement(){
if(count == A->range()) //this is not right
cerr << "Element doesn't exit" << endl;
int m = count+1;
return ((*A)[m];//this is not right either
}
thanx
matt
# 5 Re: quest
It's because you've declared A as a double pointer (Object **A). Declare it as a normal pointer (Object *A). Also, "range" doesn't seem to be defined as a member of Object, so the access A->range() won't work.
What exactly are you trying to do here?
BTW, C++ has a vector class that is much more powerful than Java's Vector. I suggest that you forget any idea you may have of transferring Java concepts and built-ins to C++ - in most cases, you'll be restricting yourself unnecessarily.
# 6 Re: quest
yah i have heard that a lot. but it is more fun to create the thing that works the way u want it to work. but never mind that.
what i m trying to do is create enumeration class as an abstract class for vector so that i can track current position in vector that is being enumerated
:o ok thanx, that is what i wanted to know. is there anyway, how i can change the code if i use double pointers knowing that the range works fine.
matt
# 7 Re: quest
Originally posted by m_prog
yah i have heard that a lot. but it is more fun to create the thing that works the way u want it to workNo, the "fun" is making the built in vector class work the way you want it to work. This can be done by using the algorithms along with the container classes. You will get a lot more farther if you studied std::vector and see what you can do to get it to do what you want. what i m trying to do is create enumeration class as an abstract class for vector so that i can track current position in vector that is being enumeratedI don't quite understand what you mean here. Why do you need to create a new vector class for this? Why create "add", "remove", etc. when it is already there? If you need to do some action because you've added or removed an element (which it sounds like this is what you want to do), then create a template class that wraps a vector<T>:
#include <vector>
template <typename T>
class MyEnumeratedVector
{
public:
MyEnumeratedVector() { }
void AddElement(T Element)
{
thisVector.push_back( T );
//
// code that I would like to do to keep track of enumerations
}
private:
std::vector<T> thisVector;
};
This is how to customize a vector to do what you want. Wrap a vector in a class and add your own custom code around the primitive vector operations such as push_back(), erase(), etc.
Regards,
Paul McKenzie
# 8 Re: quest
ok i guess i can do that also.
for this part MyEnumeratedVector()
can i have a parameter
MyEnumeratorVector(vector * thisVector) or
MyEnumeratorVector(vector & thisVector)
something like this or does it have to be MEV()?
matt