tina05 0 Newbie Poster

somebory can tell me how to swap two colum of the two dimentional array that with pointer

this is the run

I did but do not work
I was in function swap
0 0x11 0
sh: pause: command not found
I was in destructor
*** glibc detected *** ./a.out: free(): invalid pointer: 0x0991d070 ***
======= Backtrace: =========
/lib/libc.so.6[0x5d5a68]
/lib/libc.so.6(__libc_free+0x78)[0x5d8f6f]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xade801]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0xade85d]
./a.out[0x8048e1d]
./a.out[0x8048efd]
/lib/libc.so.6(__libc_start_main+0xdc)[0x5874e4]
./a.out(__gxx_personality_v0+0x51)[0x8048791]
======= Memory map: ========
00555000-0056e000 r-xp 00000000 fd:00 1403592 /lib/ld-2.4.so
0056e000-0056f000 r-xp 00018000 fd:00 1403592 /lib/ld-2.4.so
0056f000-00570000 rwxp 00019000 fd:00 1403592 /lib/ld-2.4.so
00572000-0069f000 r-xp 00000000 fd:00 1403660 /lib/libc-2.4.so
0069f000-006a1000 r-xp 0012d000 fd:00 1403660 /lib/libc-2.4.so
006a1000-006a2000 rwxp 0012f000 fd:00 1403660 /lib/libc-2.4.so
006a2000-006a5000 rwxp 006a2000 00:00 0
006a7000-006ca000 r-xp 00000000 fd:00 1405896 /lib/libm-2.4.so
006ca000-006cb000 r-xp 00022000 fd:00 1405896 /lib/libm-2.4.so
006cb000-006cc000 rwxp 00023000 fd:00 1405896 /lib/libm-2.4.so
00a1e000-00a29000 r-xp 00000000 fd:00 1406597 /lib/libgcc_s-4.1.1-20070108.so.1
00a29000-00a2a000 rwxp 0000a000 fd:00 1406597 /lib/libgcc_s-4.1.1-20070108.so.1
00a2c000-00b0b000 r-xp 00000000 fd:04 1282337 /usr/lib/libstdc++.so.6.0.8
00b0b000-00b0f000 r-xp 000de000 fd:04 1282337 /usr/lib/libstdc++.so.6.0.8
00b0f000-00b10000 rwxp 000e2000 fd:04 1282337 /usr/lib/libstdc++.so.6.0.8
00b10000-00b16000 rwxp 00b10000 00:00 0
00f37000-00f38000 r-xp 00f37000 00:00 0 [vdso]
08048000-0804a000 r-xp 00000000 fd:01 5998511 /home/math/santa_gm/numero3/a.out
0804a000-0804b000 rw-p 00001000 fd:01 5998511 /home/math/santa_gm/numero3/a.out
0991d000-0993e000 rw-p 0991d000 00:00 0
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7f19000-b7f1b000 rw-p b7f19000 00:00 0
b7f2d000-b7f2f000 rw-p b7f2d000 00:00 0
bfee6000-bfefc000 rw-p bfee6000 00:00 0

#include <iostream>
#include <string>


using namespace std;


/*TwoDimArray::TwoDimArray()
{
}
*/
TwoD::TwoD( int r, int c)
{

x = r;

y = c;

elemtD = new int *[x]; // **elemtD is a two Dim pointer in the private sector

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

elemtD[i] = new int [y];

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

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

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

TwoD::TwoD(const TwoD & ap1) // copy constructor
{

deepCopy( ap1 );



}

TwoD::~TwoD( )
{



for (int i = 0; i < x; i++)
{
delete[] elemtD[i];

delete[] elemtD;

}
}

/*void TwoD::operator =( const TwoDimArray &right1 ) // overload assigment operator give run time error
{

if (this == &right1 )

return this;

delete elemtD;

deeCopy (right1);

return *this;

}
TwoD::~TwoD( )
{


for (int i = 0; i < x; i++)
{
delete[] elemtD[i];

delete[] elemtD;

}
}

/*void TwoD::operator =( const TwoD &right1 ) // overload assigment operator give run time error
{

if (this == &right1 )

return this;

delete elemtD;

deeCopy (right1);

return *this;

}
*/


/*void TwoD:: operator[](int i, int j);// give run time erros

{
return elemtwoDarray[i][j];

}
*/


void TwoD::deepCopy(const TwoD & orig1 )
{

x = orig1.x;

y = orig1.y;

elemtD= new int *[x]; // dynamically allocated array of int of set rows length

for (int i = 0; i < x; i++)
{
elemtD[i] = new int[x]; // Fill up row until x row
}

for ( int i = 0; i < x; i++ )
{
for ( int j = 0; j < y; j++ )
{
elemtD[i][j] = orig1.elemtD[i][j];

//elemtD[j] = orig2.elemtD[j];

}

}

}

int TwoD::print( int r , int c)
{

x= r

y=c;

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

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

cout<<" " << elemtD[i][j] <<" ";
}

putchar('\n');

cout<<endl;
}
}



int TwoD::swap(int index1, int index2 )
{

x = index1;

y = index2;

int *temp;

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

temp = elemtD[y];

elemtD[ydim] = elemtD[x];

elemtD[x] = temp;

cout<<" " << elemtD[x]<<" ";

}
// putchar('\n');


cout<<endl;
}][in main function


#include <iostream>
#include <string>
#include "numero3.h"

using namespace std;



int main()
{

TwoD TwD(3,4); // Declaring the three TwoD objects containing


cout << "\nElement values in the 2D Array are:\n";



TwD.print( 3,4 ); // Creating the arrays

TwD.deepCopy(TwD);// I have a question. If I have this function in the private section how I can call it in main?

cout << "\n The Swap element values in the 2D Array are:\n";


TwD.swap( 3,4 );



system("pause");

return 0;

};