#### Declaration in header of function in struct in C++ (easy)

``````#include <iostream>
#include "Uebung8_1.h"
using std::cout;
using std::cin;
int main(){
int z;
int r;
cout << "Enter x: " << "\n";
cin >> z;
cout << "Enter y: " << "\n";
cin >> r;
Point point;
point.x = z;
point.y = r;

if (point.simsalabim(point.x, point.y) != true){
int h = point.y;
point.y = point.x;
point.x = h;
}
cout << "\n" << point.x <<"\n" << point.y;

return 0;
}
``````

Point.cpp

``````struct Point{
int x;
int y;
bool simsalabim(int x, int y){
if (x >= y){
return true;
}
else{
return false;
}

}
};
``````

Point.h

``````struct Point{ int x; int y; bool simsalabim(int x, int y);};
``````

2 个回复

``````#include "Point.h"

bool Point::simsalabim(int x, int y){
return x >= y;

}
``````

``````struct Point{
int x;
int y;
bool simsalabim(){
return (x >= y);
}
};
``````

``````if (point.simsalabim() != true){
int h = point.y;
point.y = point.x;
point.x = h;
}
``````

Point.h：

``````struct Point{
int x;
int y;
bool simsalabim();
};
``````

Point.cc：

``````#include "Point.h"

bool Point::simsalabim(){
return (x >= y);
}
``````
1 C中头文件中带有struct参数的函数声明

2018-03-16 09:51:52 1 58   c/ types
2 函数内的C ++结构声明

3 标头C ++中带有STL的函数声明

2015-04-14 20:30:15 2 88   c++
4 C ++头文件和以“= 0”结尾的函数声明

5 奇怪的C ++头文件功能声明

2019-05-17 15:30:23 1 34   swig
6 C ++标头和声明嵌套的结构和类语法

7 C在头文件中转发struct

8 是否可以直接在C ++中的结构声明中指定函数？

9 C ++禁止在将结构传递给函数时声明没有任何类型错误的…