Hello
http://i.stack.imgur.com/bzeuD.png this is a similar UMl Digram to what I have,, in FourthClass (EditorClass) I have a Function that takes the values of Arr** (pixels). and change them. I Make an object of FourthClass(Editor) that inherit from The third that has a data member of SecondClass (Image);
this is my code were I'm trying to use the 2d array I just made to rotate the 2d array 90
void Editor::newProject(){// From here
Num=1;
cout<<"Name Of The Image: ";
cin>>name;
trans();}
void Editor::trans(){
I=new Image[Num];
I[0].setID(name);
I[0].load(name); //Until here everything okay
//Now I want to call the values of pixels to do the swapping
//*****The basic rotating function******* //Should be edited
void Editor::rotate(int d){
switch (d){
case 90: for(int i=0; i<W; i++){
for(int j=i; j<H; j++){
swap(pixels[i][j], pixels[j][i]);}}
//reverse elements on row order
for(int i=0; i<W; i++){
for(int j=0; j<H/2; j++){
swap(pixels[i][j], pixels[i][H-j-1]);}
.
.
.
}
Since pixels** is a private data member of the ImageClass (SecondClass) I need to use getpixel function
1 2
RGB Image::getPixel(int i,int j){
return pixels[i][j];} //Pixels are a 2D array Type class RGB
Here I tried to use rotate function calling getPixel
1 2 3 4 5 6
for (int r=0; r<(I[0].getW()); r++) {
for (int c=0 ; c<(I[0].getH()); c++) {
swap(I[0].getPixel(r, c), I[0].getPixel(r, c))}
.
.
.
I used getPixel so I could call each element one by one to do the swapping but an error occur says "No matching swap function"
I don't know why that happen and how to fix it
It would appear the getPixel class returns a copy of the RGB instance in question, so swapping them would have no effect.
Your compiler is barfing because the unnamed variable returned from getPixel is a temporary and you're trying to bind that temporary to a non-const reference (as it wouldn't make sense for swap to take values by const reference) which can't be done.
but there was no change in the array values (seeing the image I have)..
It should flip the image around the horizontal axis. Of course, that's all in the second loop. The first loop has no effect since it works beyond the halfway point and undoes in the second half what it did in the first.
Rotating 90 degrees (or 270 degrees) isn't a symmetric operation. I don't think swap is going to be the answer for you.