我把身体的 warning 当成了误报
2026/9/27 7:00:32
#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; struct demo1 { int a; void print_a() { cout << a << endl; } }; int main(int argc,char **argv) { demo1 test; test.a = 10; test.print_a(); }#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; struct demo1 { int a; bool operator()(int c , int b) { int sum = c + b; cout << sum << endl; return true ; } }; int main(int argc,char **argv) { demo1 test; bool d = test(10,20); cout << d << endl; demo1 test2; demo1 *p = &test2; (*p)(20,30); }#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; int main(int argc,char **argv) { double b[2] = {10,20}; const double *const abc = b; for(int i = 0 ; i < 2;i++) { cout << abc[i] << endl; } }#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; struct Student { double age; }; int main(int argc,char **argv) { Student s; s.age = 20; Student *p = new Student; (*p).age = 10; cout << (*p).age << endl; cout << s.age << endl; }#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; struct Student { template<typename T> void operator()(T b) { cout << b << endl; } }; int main(int argc,char **argv) { Student s; Student *p = new Student; s(5); (*p)(6); }struct Foo { template<typename T> void f1(T a) { } // ← 上面那行 template 只管 f1 template<typename U> // ← f2 要再写一次(参数名可以不同) void f2(U b) { } // ← 这行只管 f2 void f3() { } // ← 不是模板,不需要 template };#include "hello.h"//自己定义的头文件用"" #include <iostream>//标准库的头文件用<> using namespace std; template<typename T> struct Student { T age; Student (T a) : age(a) {} void operator()(T b) { cout << b << endl; } }; int main(int argc,char **argv) { Student<double> s(1); Student<double> *p = new Student<double>(2); s(3); (*p)(4); }