2014-08-31 90 views
1

假设图像是我的对象文件“a”,我创建了另一个名为b的对象文件来旋转图像。我给了(j,i)一个给(i,j)的b,但是我的代码不工作,因为我没有正确地使用那个称为operator的函数,我有“//”我尝试过的东西,但是我不断出现错误,我该怎么办? rgbapixels是一个像素类,就像png是一个图像类;如何旋转给定的图像?

在PNG.h中,我们现在将函数定义为;

#include <iostream> 
#include "rgbapixel.h" 
class PNG 
{ 
public: 
RGBAPixel * operator()(size_t x, size_t y); 
/** 
* Const pixel access operator. Const version of the previous 
* operator(). Does not allow the image to be changed via the 
* pointer. 
* @param x X-coordinate for the pixel pointer to be grabbed from. 
* @param y Y-cooridnate for the pixel pointer to be grabbed from. 
* @return A pointer to the pixel at the given coordinates (can't 
*  change the pixel through this pointer). 
*/ 
size_t width() const; // returns width 
size_t width() const; 
private: 
// storage 
size_t _width; 
size_t _height; 
RGBAPixel * _pixels; 
}; 

函数在png.cpp中为我们实现。所以,在main.cpp中,我有我的代码来使用它们;

#include <algorithm> 
#include <iostream> 

#include "rgbapixel.h" 
#include "png.h" 
using namespace std; 
int main() 
{ 
cout << "me..........." << endl; 
PNG a("I have put the image in "a" here"); 
PNG b; 
for(size_t i = 0; i < a.width(); i++) 
{ 
for(size_t j = 0; j <a.height(); j++) 
{ 
// *b(i, j) = *a(j, i);        erata 
// b(i,j) = RGBAPixel * operator()(size_t x, size_t y); 
// b(i, j) = operator()(i, j);    
//b(i,j) = *operator(i,j); 
//b(j,i) = a*operator(i,j); 
//b(j,i) = a.operator(i,j); 
//b(j, i) = a.*operator(i,j); 
} 
} 
return 0; 
} 

我得到错误使用该功能,我不能说出了什么问题。所以,我不知道我的alogarithm是否会得到旋转的图像

有些错误;

[[email protected] lab_intro]$ make 
clang++ -std=c++1y -stdlib=libc++ -c -g -O0 -Wall -Wextra -pedantic main.cpp 
main.cpp:24:29: error: expected ')' 
b(i,j) = *operator(i,j); 
        ^
main.cpp:24:28: note: to match this '(' 
b(i,j) = *operator(i,j); 
       ^
main.cpp:24:20: error: use of undeclared 'operator()' 
b(i,j) = *operator(i,j); 
     ^
2 errors generated. 
make: *** [main.o] Error 1 

感谢

回答

0

()运营商获取在与该运营商的类的实例被调用使用作为函数调用。

所以,随着您的PNG类,和它的两个实例名为ab,他们()运营商将得到根本援引为:

a(i, j) 

b(i, j) 

由于您()运营商的回报一个RGBAPixel *,这样一个伪函数调用的最终结果是一个指针,我认为应该解除引用。

在您的示例代码的第一注释掉行:

// *b(i, j) = *a(j, i); 

这在我看来就像你()操作的正确用法。我没有看到编译该问题的任何问题。

+0

但它失败了,它给了我错误; clang ++ -std = C++ 1y -stdlib = libC++ -c -g -O0 -Wall -Wextra -pedantic main.cpp main.cpp:21:62:error:使用未声明的标识符'erata' * b(i ,j)= * a(j,i); erata ^ 生成1个错误。 make:*** [main.o]错误1 – user124627 2014-09-01 01:10:19

+0

无论如何,您的错误消息明确提及'erata'。该错误消息似乎与赋值语句没有任何关系。有用的提示:在放弃并要求其他人寻求帮助之前,请至少阅读三次错误消息。尤其是铿锵的错误信息,因其清晰度和实用性而闻名。 – 2014-09-01 01:12:49

+0

它的工作原理,但出于某种原因,当我输出图像在“B”,它的空,它表明没有像素被复制。给出警告; ....... [EasyPNG]:警告:尝试访问不存在的像素(511,383); 截断请求以适合范围[0,0] x [0,0]。 [jonathan2 @ linux-a1 lab_intro] $ – user124627 2014-09-01 02:18:35

0

你不应该调用以这种方式操作的功能,而不是这样做:

*b(i, j) = *a(j, i); 
+0

但它失败了,它给了我错误; clang ++ -std = C++ 1y -stdlib = libC++ -c -g -O0 -Wall -Wextra -pedantic main.cpp main.cpp:21:62:error:使用未声明的标识符'erata'* b(i,j )= * a(j,i);生成的erata^1错误。使:*** [main.o]错误1 – user124627 2014-09-01 01:12:32

+1

谢谢你们,我apreciate它 – user124627 2014-09-01 07:20:14