invalid conversion from âint*â to âintâ

the constructor is
TwoD<T>::TwoD( int x, int y)
{
r = x;

c = y;

elet = new int *[r];

for (int i = 0; i < r; i++){

elet[i] = new int [c];

}
for (int i=0; i < r; i++){

for(int j=0; j < c; j++){

elet[i][j] = i*j;
}
}
}

--------------------------

the swap function is

template <class T>
TwoDimArray<T> TwoD<T>::swap(int r, int c )
{
x=r;
y=c;

int *temp;
*temp = elet[x];
elet[x] = elet[y];
elet[xdim] =* temp;
}
---------------------------------
the errors are


P.cpp:30: instantiated from here
TwoD.cpp:153: error: invalid conversion from âint*â to âintâ
TwoD.cpp:155: error: invalid conversion from âintâ to âint*â

any idea fro the mistake ???

in the main the call is:
int main()
{
TwD<int> TwoD2

TwD2.swap( 3,4 );

return 0;
}





What's up with this syntax elet = new int *[r]; O.O ?
kevinchkin: That's perfectly valid.

I think you meant:
1
2
3
4
int *temp;
temp = elet[x];
elet[x] = elet[y];
elet[xdim] = temp;
Oh yeah, Damn it, didn't see he was allocating the memory over there. Sorry, my bad.
Hi guys

the asswerd was ok but the result of the zwap was not????/

What is wrong in the swap, any edea


*** glibc detected *** ./a.out: free(): invalid pointer: 0x00b0beb8 ***
======= Backtrace: =========
/lib/libc.so.6[0x173a68]
/lib/libc.so.6(__libc_free+0x78)[0x176f6f]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xade801]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0xade85d]
./a.out[0x8048b94]
./a.out(__gxx_personality_v0+0x1ee)[0x80488f6]
/lib/libc.so.6(__libc_start_main+0xdc)[0x1254e4]
./a.out(__gxx_personality_v0+0x59)[0x8048761]
======= Memory map: ========
00110000-0023d000 r-xp 00000000 fd:00 1403660 /lib/libc-2.4.so
0023d000-0023f000 r-xp 0012d000 fd:00 1403660 /lib/libc-2.4.so
0023f000-00240000 rwxp 0012f000 fd:00 1403660 /lib/libc-2.4.so
00240000-00243000 rwxp 00240000 00:00 0
00555000-0056e000 r-xp 00000000 fd:00 1403592 /lib/ld-2.4.so
0056e000-0056f000 r-xp 00018000 f
Well, your swap is probably wrong. The fourth line assigns to elet[xdim] instead of elet[y], for some reason.
yes, look like I do not saving any number and the destructor do his job????

any idea.........


this is after the call from main

0x8586008 0x8586008 0x8586008 0x8586008

0x8586008 0x8586008 0x8586008 0x8586008

0x8586008 0x8586008 0x8586008 0x8586008
Topic archived. No new replies allowed.