我有个问题.我写了这段代码,ahac和main.c:
档案:啊
#ifndef _a_H
#define _a_H
int poly (int a, int b, int c, int x);
int square (int x)
{
return x*x;
}
#endif // _a_H
Run Code Online (Sandbox Code Playgroud)
档案:ac
#include "a.h"
int poly (int a, int b, int c, int x)
{
return a*square(x) + b * x +c;
}
Run Code Online (Sandbox Code Playgroud)
file:main.c
#include <stdio.h>
#include "a.h"
int main()
{
int p1 = poly1 (1 ,2 , 1, 5);
int p2 = poly2 (1 ,1 , 3, 5);
printf ("p1 = %d, p2 …Run Code Online (Sandbox Code Playgroud) 我必须在C中使用char []并且我想在它们之间交换,只需将指针交换到数组而不是一次只有一个char,所以我编写了这段代码:
#include <stdio.h>
void fastSwap (char **i, char **d)
{
char *t = *d;
*d = *i;
*i = t;
}
int main ()
{
char num1[] = "012345678910";
char num2[] = "abcdefghujk";
fastSwap ((char**)&num1,(char**)&num2);
printf ("%s\n",num1);
printf ("%s\n",num2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到这个输出(注意最后4个字符)
abcdefgh8910 01234567ujk
当我期待:
abcdefghujk 012345678910
注意:我正在使用64位Linux系统.
我试图在C++中预先形成运算符重载; 由于某种原因,编译继续给我错误
错误:'bool Matrix :: operator ==(const Matrix&,const Matrix&)'必须只有一个参数
现在,我知道有一些方法可以用一个参数使用它,但我明白通过使用朋友我可以这样做,但它仍然无法正常工作.
这是我的代码,
提前致谢.
class Matrix{
public:
Matrix();
friend bool operator==(Matrix &mtrx1,Matrix &mtrx2);
friend bool operator!=(Matrix &mtrx1,Matrix &mtrx2);
protected:
std::vector<Cell> _matrix;
int _row;
int _col;
};
inline bool Matrix::operator==(const Matrix& mtrx1, const Matrix& mtrx2){
/* .......... */
}
Run Code Online (Sandbox Code Playgroud)