c++包括<复杂>导致文件字符串出现语法错误复杂>
错误 3 错误 C2059:语法错误:')' c:\program files\microsoft Visual Studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl 错误 6 错误 C2059: 语法错误: ')' c:\program files\microsoft Visual Studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl 错误 1 错误 C2143:语法错误:在“字符串”c:\program files\microsoft Visual Studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl 之前缺少“)” 错误 4 错误 C2143:语法错误:在“字符串”c:\program files\microsoft Visual Studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl 之前缺少“)” 错误 2 错误 C2665: 'swprintf' : 2 个重载均无法转换所有参数类型 c:\program files\microsoft Visual Studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl 错误 5 错误 C2665: 'swprintf' : 2 个重载均无法转换所有参数类型 c:\program files\microsoft Visual Studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl
我不明白这个错误,因为它说错误出在文件字符串中,该文件是VS2010提供的锁定文件。其次,我什至没有使用字符串,第三,包含复杂怎么可能与库字符串有任何关系?
尽管包含复杂会导致我的项目文件中出现错误,但我启动了一个全新的文件来测试包含它,并且那里没有发生错误。
#include "Image.h"
#include <iostream>
#include <complex>
using namespace std;
#define Usage "makeSwirl inImg outImg coeff\n"
/*
* arg1 is the image to transform.
* arg2 is the swirl coefficient
* Returns image with enhanced edges.
*/
Image swirl(const Image&, const float&);
/*
* arg1 is the image within which the pixel to be transformed is located.
* arg2&3&4 are the row, colum, and channel of the pixel to transform.
* arg5 is the swirl coefficient
* arg6&7 are the rows and cols of arg1.
* returns transformed pixel.
*/
float onePixelSwirl(const Image&, const int&, const int&, const int&, const double&, const int&, const int&);
int main(int argc, char **argv)
{
// Check for proper number of arguments.
if(argc != 4)
{
cout << Usage;
exit(3);
}
// Read in image specified by user.
const Image IN_IMG = readImage(argv[1]);
// Create output image with oil effect.
Image outImg = swirl(IN_IMG, atof(argv[3]));
// Output the image
writeImage(outImg, argv[2]);
// Success!
return(0);
}
Image swirl(const Image& IN_IMG, const float& COEFF)
{
Image outImg;
// Allocate memory
const int ROWS = IN_IMG.getRow();
const int COLS = IN_IMG.getCol();
const int CHANNELS = IN_IMG.getChannel();
outImg.createImage(ROWS, COLS, IN_IMG.getType());
// Perform edge effect
for (int k = 0; k < CHANNELS; ++k)
for (int i = 0; i < ROWS; ++i)
for (int j = 0; j < COLS; ++j)
outImg(i,j,k) = onePixelSwirl(IN_IMG, i, j, k, COEFF, ROWS, COLS);
return outImg;
}
float onePixelSwirl(const Image& IN_IMG, const int& ROW, const int& COL,
const int& CHANNEL, const double& COEFF, const int& ROWS, const int& COLS)
{
// define shift of origin
//const double X_SHIFT = ROWS/2.0;
//const double Y_SHIFT = COLS/2.0;
//const complex<double> NEW_SHIFTED(ROW - X_SHIFT, COL - Y_SHIFT);
//const double r = abs(NEW_SHIFTED);
//const complex<double> OLD_SHIFTED = polar(r, arg(NEW_SHIFTED) + r/COEFF);
//const int OLD_ROW = OLD_SHIFTED.real() <= ROWS ? OLD_SHIFTED.real() : ROWS;
//const int OLD_COL = OLD_SHIFTED.imag() <= COLS ? OLD_SHIFTED.imag() : COLS;
//return IN_IMG(OLD_ROW, OLD_COL, CHANNEL);
return 0;
}
我将 include 语句放在上面,包括 image.h,编译错误就消失了。这是 image.h 如果有人能找出问题:
/********************************************************************
* Image.h - header file of the Image library which defines
* a new class "Image" and the associated member functions
*
* Author: Hairong Qi, [email protected], ECE, University of Tennessee
*
* Created: 02/05/02
*
* Note:
* This is a simple C++ library for image processing.
* The purpose is not high performance, but to show how
* the algorithm works through programming.
* This library can only read in PGM/PPM format images.
*
* Modification:
* 07/31/09 - moving header files for colorProcessing, imageIO, and
* matrixProcessing to this file
* 01/22/06 - reorganize the Image library such that the Image class
* only contains member functions related to the most
* fundamental image operation
* 11/12/05 - add wavelet transform function
* 09/26/05 - add Fourier transform related functions
* 09/07/05 - add overloading function for "/"
* 09/07/05 - modify createImage() function
* 09/07/05 - fix problems with copy constructor
* 08/07/05 - regrouping functions
********************************************************************/
#ifndef IMAGE_H
#define IMAGE_H
#include <iostream>
#include <cmath>
using namespace std;
#define PGMRAW 1 // magic number is 'P5'
#define PPMRAW 2 // magic number is 'P6'
#define PGMASCII 3 // magic number is 'P2'
#define PPMASCII 4 // magic number is 'P3'
#define GRAY 10 // gray-level image
#define BINARY 11 // binary image
#define NBIT 8
#define L ( pow(2.0,NBIT)-1 ) // the largest intensity represented by NBIT
class Image {
friend ostream & operator<<(ostream &, Image &);
friend Image operator/(Image &, double); // image divided by a scalar
friend Image operator*(Image &, double); // image multiplied by a scalar
friend Image operator+(Image &, double); // image add a scalar
friend Image operator-(Image &, double); // image subtract a scalar
public:
// constructors and destructor
Image(); // default constructor
Image(int, // constructor with row
int, // column
int t=PGMRAW); // type (use PGMRAW, PPMRAW,
// PGMASCII, PPMASCII)
Image(const Image &); // copy constructor
~Image(); // destructor
// create an image
void createImage(); // create an image, parameters all set
void createImage(int, // create an image with row
int c=1, // column (default 1, a column vector)
int t=PGMRAW); // and type, default is PGMRAW
void initImage(float init=0.0); // initiate the pixel value of an img
// the default is 0.0
// get and set functions
int getRow() const; // get row # / the height of the img
int getCol() const; // get col # / the width of the image
int getChannel() const; // get channel number of the image
int getType() const; // get the image type
float getMaximum() const; // get the maximum pixel value
void getMaximum(float &, // return the maximum pixel value
int &, int &); // and its indices
float getMinimum() const; // get the mininum pixel value
void getMinimum(float &, // return the minimum pixel value
int &, int &); // and its indices
Image getRed() const; // get the red channel
Image getGreen() const; // get the green channel
Image getBlue() const; // get the blue channel
Image getImage(int) const; // get the kth channel image,
// k starts at 0
void setRow(int); // set row number
void setCol(int); // set column number
void setChannel(int); // set the number of channel
void setType(int t=PGMRAW); // set the image type
void setRed(Image &); // set the red channel
void setGreen(Image &); // set the green channel
void setBlue(Image &); // set the blue channel
void setImage(Image &, int); // set the kth channel image,
// k starts at 0
// operator overloading functions
float & operator()(int, // operator overloading (i,j,k)
int c = 0, // when c=k=0, a column vector
int k = 0) const;
const Image operator=(const Image &); // = operator overloading
Image operator+(const Image &) const; // overloading + operator
Image operator-(const Image &) const; // overloading - operator
Image operator*(const Image &) const; // overloading pixelwise *
Image operator/(const Image &) const; // overloading pixelwise division
Image operator->*(const Image &) const; // overloading ->* operator
// (matrix multiplication)
bool IsEmpty() const { return (image==NULL); }
private:
int row; // number of rows / height
int col; // number of columns / width
int channel; // nr of channels (1 for gray, 3 for color)
int type; // image type (PGM, PPM, etc.)
int maximum; // the maximum pixel value
float *image; // image buffer
};
////////////////////////////////////
// image I/O
Image readImage(char *); // read image
void writeImage(Image &, // write an image
char *,
int flag=0); // flag for rescale, rescale when == 1
Image rescale(Image &, // rescale an image
float a=0.0, // lower bound
float b=L); // upper bound
////////////////////////////////////
// color processing routines
Image RGB2HSI(Image &); // convert from RGB to HSI model
Image HSI2RGB(Image &); // convert from HSI to RGB model
////////////////////////////////////
// matrix manipulation
Image transpose(Image &); // image transpose
Image inverse(Image &); // image inverse
Image pinv(Image &); // image pseudo-inverse
Image subImage(Image &, // crop an image
int, // starting row index
int, // starting column index
int, // ending row index
int); // ending column index
#endif
Error 3 error C2059: syntax error : ')' c:\program files\microsoft visual studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl
Error 6 error C2059: syntax error : ')' c:\program files\microsoft visual studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl
Error 1 error C2143: syntax error : missing ')' before 'string' c:\program files\microsoft visual studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl
Error 4 error C2143: syntax error : missing ')' before 'string' c:\program files\microsoft visual studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl
Error 2 error C2665: 'swprintf' : none of the 2 overloads could convert all the argument types c:\program files\microsoft visual studio 10.0\vc\include\string 758 1 ECE572_001_Project1_swirl
Error 5 error C2665: 'swprintf' : none of the 2 overloads could convert all the argument types c:\program files\microsoft visual studio 10.0\vc\include\string 767 1 ECE572_001_Project1_swirl
I don't understand this error, because it says the error is in the file string, which is a locked file provided by VS2010. Second, I'm not even using string, and third, how could including complex have anything to do with the library string?
Even though including complex causes the error in my project file, I started a whole new file to test including it, and the error didn't happen there.
#include "Image.h"
#include <iostream>
#include <complex>
using namespace std;
#define Usage "makeSwirl inImg outImg coeff\n"
/*
* arg1 is the image to transform.
* arg2 is the swirl coefficient
* Returns image with enhanced edges.
*/
Image swirl(const Image&, const float&);
/*
* arg1 is the image within which the pixel to be transformed is located.
* arg2&3&4 are the row, colum, and channel of the pixel to transform.
* arg5 is the swirl coefficient
* arg6&7 are the rows and cols of arg1.
* returns transformed pixel.
*/
float onePixelSwirl(const Image&, const int&, const int&, const int&, const double&, const int&, const int&);
int main(int argc, char **argv)
{
// Check for proper number of arguments.
if(argc != 4)
{
cout << Usage;
exit(3);
}
// Read in image specified by user.
const Image IN_IMG = readImage(argv[1]);
// Create output image with oil effect.
Image outImg = swirl(IN_IMG, atof(argv[3]));
// Output the image
writeImage(outImg, argv[2]);
// Success!
return(0);
}
Image swirl(const Image& IN_IMG, const float& COEFF)
{
Image outImg;
// Allocate memory
const int ROWS = IN_IMG.getRow();
const int COLS = IN_IMG.getCol();
const int CHANNELS = IN_IMG.getChannel();
outImg.createImage(ROWS, COLS, IN_IMG.getType());
// Perform edge effect
for (int k = 0; k < CHANNELS; ++k)
for (int i = 0; i < ROWS; ++i)
for (int j = 0; j < COLS; ++j)
outImg(i,j,k) = onePixelSwirl(IN_IMG, i, j, k, COEFF, ROWS, COLS);
return outImg;
}
float onePixelSwirl(const Image& IN_IMG, const int& ROW, const int& COL,
const int& CHANNEL, const double& COEFF, const int& ROWS, const int& COLS)
{
// define shift of origin
//const double X_SHIFT = ROWS/2.0;
//const double Y_SHIFT = COLS/2.0;
//const complex<double> NEW_SHIFTED(ROW - X_SHIFT, COL - Y_SHIFT);
//const double r = abs(NEW_SHIFTED);
//const complex<double> OLD_SHIFTED = polar(r, arg(NEW_SHIFTED) + r/COEFF);
//const int OLD_ROW = OLD_SHIFTED.real() <= ROWS ? OLD_SHIFTED.real() : ROWS;
//const int OLD_COL = OLD_SHIFTED.imag() <= COLS ? OLD_SHIFTED.imag() : COLS;
//return IN_IMG(OLD_ROW, OLD_COL, CHANNEL);
return 0;
}
I put the include statement above including image.h, and the compilation bugs vanished. Here is image.h if someone could figure out the problem:
/********************************************************************
* Image.h - header file of the Image library which defines
* a new class "Image" and the associated member functions
*
* Author: Hairong Qi, [email protected], ECE, University of Tennessee
*
* Created: 02/05/02
*
* Note:
* This is a simple C++ library for image processing.
* The purpose is not high performance, but to show how
* the algorithm works through programming.
* This library can only read in PGM/PPM format images.
*
* Modification:
* 07/31/09 - moving header files for colorProcessing, imageIO, and
* matrixProcessing to this file
* 01/22/06 - reorganize the Image library such that the Image class
* only contains member functions related to the most
* fundamental image operation
* 11/12/05 - add wavelet transform function
* 09/26/05 - add Fourier transform related functions
* 09/07/05 - add overloading function for "/"
* 09/07/05 - modify createImage() function
* 09/07/05 - fix problems with copy constructor
* 08/07/05 - regrouping functions
********************************************************************/
#ifndef IMAGE_H
#define IMAGE_H
#include <iostream>
#include <cmath>
using namespace std;
#define PGMRAW 1 // magic number is 'P5'
#define PPMRAW 2 // magic number is 'P6'
#define PGMASCII 3 // magic number is 'P2'
#define PPMASCII 4 // magic number is 'P3'
#define GRAY 10 // gray-level image
#define BINARY 11 // binary image
#define NBIT 8
#define L ( pow(2.0,NBIT)-1 ) // the largest intensity represented by NBIT
class Image {
friend ostream & operator<<(ostream &, Image &);
friend Image operator/(Image &, double); // image divided by a scalar
friend Image operator*(Image &, double); // image multiplied by a scalar
friend Image operator+(Image &, double); // image add a scalar
friend Image operator-(Image &, double); // image subtract a scalar
public:
// constructors and destructor
Image(); // default constructor
Image(int, // constructor with row
int, // column
int t=PGMRAW); // type (use PGMRAW, PPMRAW,
// PGMASCII, PPMASCII)
Image(const Image &); // copy constructor
~Image(); // destructor
// create an image
void createImage(); // create an image, parameters all set
void createImage(int, // create an image with row
int c=1, // column (default 1, a column vector)
int t=PGMRAW); // and type, default is PGMRAW
void initImage(float init=0.0); // initiate the pixel value of an img
// the default is 0.0
// get and set functions
int getRow() const; // get row # / the height of the img
int getCol() const; // get col # / the width of the image
int getChannel() const; // get channel number of the image
int getType() const; // get the image type
float getMaximum() const; // get the maximum pixel value
void getMaximum(float &, // return the maximum pixel value
int &, int &); // and its indices
float getMinimum() const; // get the mininum pixel value
void getMinimum(float &, // return the minimum pixel value
int &, int &); // and its indices
Image getRed() const; // get the red channel
Image getGreen() const; // get the green channel
Image getBlue() const; // get the blue channel
Image getImage(int) const; // get the kth channel image,
// k starts at 0
void setRow(int); // set row number
void setCol(int); // set column number
void setChannel(int); // set the number of channel
void setType(int t=PGMRAW); // set the image type
void setRed(Image &); // set the red channel
void setGreen(Image &); // set the green channel
void setBlue(Image &); // set the blue channel
void setImage(Image &, int); // set the kth channel image,
// k starts at 0
// operator overloading functions
float & operator()(int, // operator overloading (i,j,k)
int c = 0, // when c=k=0, a column vector
int k = 0) const;
const Image operator=(const Image &); // = operator overloading
Image operator+(const Image &) const; // overloading + operator
Image operator-(const Image &) const; // overloading - operator
Image operator*(const Image &) const; // overloading pixelwise *
Image operator/(const Image &) const; // overloading pixelwise division
Image operator->*(const Image &) const; // overloading ->* operator
// (matrix multiplication)
bool IsEmpty() const { return (image==NULL); }
private:
int row; // number of rows / height
int col; // number of columns / width
int channel; // nr of channels (1 for gray, 3 for color)
int type; // image type (PGM, PPM, etc.)
int maximum; // the maximum pixel value
float *image; // image buffer
};
////////////////////////////////////
// image I/O
Image readImage(char *); // read image
void writeImage(Image &, // write an image
char *,
int flag=0); // flag for rescale, rescale when == 1
Image rescale(Image &, // rescale an image
float a=0.0, // lower bound
float b=L); // upper bound
////////////////////////////////////
// color processing routines
Image RGB2HSI(Image &); // convert from RGB to HSI model
Image HSI2RGB(Image &); // convert from HSI to RGB model
////////////////////////////////////
// matrix manipulation
Image transpose(Image &); // image transpose
Image inverse(Image &); // image inverse
Image pinv(Image &); // image pseudo-inverse
Image subImage(Image &, // crop an image
int, // starting row index
int, // starting column index
int, // ending row index
int); // ending column index
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多值得怀疑的地方,但最主要的是
L
的定义。如果我记得的话,L
用于指示 Unicode 字符串文字,如L"Some Unicode text"
中所示。
似乎很可能使用它。通过在
之前包含Image.h
,您就重新定义了它。这也可以解释对 swprintf() 的错误调用。既然您在
Image.h
中没有使用L
,那么有什么理由在那里声明它呢?如果 L 是接口的一部分并且实际上需要位于头文件中,请考虑将其重命名为不太可能引发名称冲突的名称。其他看起来可疑但不一定是问题的事情:您无缘无故地将
包含在Image.h
中。一般来说,您应该只包含您实际需要的文件。一个更大的问题是标头中的using namespace std
。这几乎总是一个坏主意,因为它将 std 命名空间中的每个名称拉入包含此头文件的每个文件的本地范围。它大大增加了名称冲突的可能性,而这些冲突可能很难解决(如您所见)There's a number of things that are suspicious but the main one is the definition of
L
. If I recall,L
is used to indicate a Unicode string literal as inL"Some Unicode text"
. It seems likely that<complex>
uses this. By includingImage.h
before<complex>
, you've redefined it. This would also explain the broken calls toswprintf()
.Since you don't use
L
inImage.h
is there any reason to declare it there? IfL
is part of the interface and actually needs to be in the header file, consider renaming it to something less likely to provoke a name conflict.Other things that look suspicious but aren't necessarily the problem here: You've included
<cmath>
inImage.h
for no apparent reason. Generally, you should only include the files you actually need. A bigger issue is theusing namespace std
in the header. This is almost always a bad idea since it pulls every name in the std namespace into the local scope of every file that includes this header file. It greatly increases the chance of name collisions that could be tricky to sort out (as you can see)