G
Gonzalo Aguirre
i have three classes like this
class foo{
attrib_1;
..
..
public:
..
};
/************ BAR ***********/
class bar{
class foo *f;
int position;
...
public:
foo(int);
foo & operator[](int);
};
foo:foo(int elem){
f = new foo[elem];
...
}
foo &
bar:perator[](int index){
// check code omited
return f[index];
}
/************** STACK ***********/
class stack{
class bar b; //i use bar as a vector
int sp; //stack pointer
public:
stack();
foo & pop();
void push(foo &);
};
stack::stack{
b(QUANT); // <--- create a vector of a constant value
sp = 1;
}
foo &
stack:op(){
// check code omited
return b[sp];
}
void
stack:ush(foo & f){
(2) b[++sp] = f; // <---- operator[] as lvalue ***** (2) *******
}
/************* MAIN *************/
int
main(void){
foo f(1,2);
bar b(5); // <-- vector of 5 elements (see foo:foo(int))
stack s;
(1) b[1] = f; // <-- which method invoke? ()
s.push(f); // <-- this try to call operator[]
return 0;
}
why if i assing in (2) as in (1), or looks like that, they don't call the
same method??
thank in advance
class foo{
attrib_1;
..
..
public:
..
};
/************ BAR ***********/
class bar{
class foo *f;
int position;
...
public:
foo(int);
foo & operator[](int);
};
foo:foo(int elem){
f = new foo[elem];
...
}
foo &
bar:perator[](int index){
// check code omited
return f[index];
}
/************** STACK ***********/
class stack{
class bar b; //i use bar as a vector
int sp; //stack pointer
public:
stack();
foo & pop();
void push(foo &);
};
stack::stack{
b(QUANT); // <--- create a vector of a constant value
sp = 1;
}
foo &
stack:op(){
// check code omited
return b[sp];
}
void
stack:ush(foo & f){
(2) b[++sp] = f; // <---- operator[] as lvalue ***** (2) *******
}
/************* MAIN *************/
int
main(void){
foo f(1,2);
bar b(5); // <-- vector of 5 elements (see foo:foo(int))
stack s;
(1) b[1] = f; // <-- which method invoke? ()
s.push(f); // <-- this try to call operator[]
return 0;
}
why if i assing in (2) as in (1), or looks like that, they don't call the
same method??
thank in advance