G
Gernot Frisch
See this example:
class ds
{
public:
ds() {dat[0]='\0';}
ds(int i) {sprintf(dat, "%d", i);}
ds(ds& s) {strcpy(dat, s.dat);}
operator int(){
int i = atoi(dat);
return i;
}
char dat[50];
};
ds operator+(ds& a, ds& b) {ds c(a); strcat(c.dat, b.dat); return c;}
ds operator+(int a, ds& b) {ds c(a); strcat(ds(c).dat, b.dat); return
c;}
ds operator+(ds& a, int b) {ds c(a); strcat(c.dat, ds(b).dat); return
c;}
int main(int char**)
{
ds a(1),b(2),c(3);
a = b+c+7;
}
first a+b = "23". That's fine. Now "23"+7, the "23" get's cased to an
(int) before adding. How can I make the adding of +(ds, int) happen
first?
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
class ds
{
public:
ds() {dat[0]='\0';}
ds(int i) {sprintf(dat, "%d", i);}
ds(ds& s) {strcpy(dat, s.dat);}
operator int(){
int i = atoi(dat);
return i;
}
char dat[50];
};
ds operator+(ds& a, ds& b) {ds c(a); strcat(c.dat, b.dat); return c;}
ds operator+(int a, ds& b) {ds c(a); strcat(ds(c).dat, b.dat); return
c;}
ds operator+(ds& a, int b) {ds c(a); strcat(c.dat, ds(b).dat); return
c;}
int main(int char**)
{
ds a(1),b(2),c(3);
a = b+c+7;
}
first a+b = "23". That's fine. Now "23"+7, the "23" get's cased to an
(int) before adding. How can I make the adding of +(ds, int) happen
first?
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com