【发布时间】:2014-08-31 23:44:03
【问题描述】:
假设图像是 i 对象文件“a”,我创建了另一个名为 b 的对象文件来旋转图像。我将 a 的 (j,i) 提供给 b 的 (i,j),但我的代码无法正常工作,因为没有正确使用名为 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;
}
我在使用该功能时遇到错误,我不知道出了什么问题。所以,我不知道我的算法是否会让图像旋转
一些错误;
[jonathan2@linux-a1 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
谢谢
【问题讨论】:
标签: c++ image function class header-files