Something about Compile error

本文探讨了C++中常见的编译错误,如未在类定义后添加分号、尝试在没有实例化对象的情况下调用成员函数等问题,并通过具体代码示例展示了如何修正这些错误。

A strange compile error!

   error :expected unqualified-id before ‘using’

It occurs When a class is defined in the header file that contains no added the semicolon:

    Class xxxx
    {
     ...
     };  // that is the semicolon.
#include<iostream>
#include"counter1.h"
#include"counter2.h"
using namespace std;
int main() {
    counter2::set(3);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        counter1::count();
    }
    for (int i = 0; i < m; i++) {
        counter2::count();
    }
    counter1 x;
    x();
    cout << counter1::counter << endl;
    cout << counter2::counter << endl;
}
// wrong code:
#include<iostream>
using namespace std;
class counter2 {
public:
void set(int x) {
counter = x;
}
void count() {
counter++;
}
private:
int counter;
};
class counter1 {
 public:
     int count();
     static int counter;
};
int counter1::count() {
    counter++;
}
// After modify the code.
#include<iostream>
namespace counter2 {
    int counter = 0;
    void set(int x) {
        counter = x;
    }
    void count() {
        counter++;
    }
};
class counter1 {
 public:
    counter1() {}
    ~counter1() {
        counter = 0;
    }
    void operator()() {
/*The first () is the name of the operator - it's the operator that is invoked when you use () on the object. The second () is for the parameters, of which there are none.*/
 // error: no match for call to ‘(counter1) ()’
        ++counter;
    }
    static void count();
//error: cannot call member function ‘void counter1::count()’ without object,add "static"is ok
    static int counter;
};
void counter1::count() {
    counter++;
}
int counter1::counter = 0;
//Without this sentence,it will be "In function `counter1::count()', undefined reference to `counter1::counter'"

compile error:

main.cpp:6: error: cannot call member function ‘void counter2::set(int)’ without object
main.cpp:10: error: cannot call member function ‘int counter1::count()’ without object
main.cpp:13: error: cannot call member function ‘void counter2::count()’ without object
main.cpp:16: error: no match for call to ‘(counter1) ()’
counter2.h:12: error: ‘int counter2::counter’ is private
main.cpp:18: error: within this context
counter2.h:12: error: invalid use of non-static data member ‘counter2::counter’
main.cpp:18: error: from this location

#include <iostream>
#include <string>
using namespace std;
//using namespace编译指示,使在C++标准类库中定义的名字在本程序中可以使用
//否则,iostream,string 等c++标准类就不可见了,编译就会出错。
//两个在不同命名空间中定义的名字相同的变量
namespace myown1{
    string user_name = "myown1";
}
namespace myown2{
    string user_name = "myown2";
}
int main()
{
    cout<< "/n"
    << "Hello, " 
    << myown1::user_name //用命名空间限制符myown1访问变量user_name
    << "... and goodbye!/n";

    cout<< "/n"
    << "Hello, " 
    << myown2::user_name //用命名空间限制符myown2访问变量user_name
    << "... and goodbye!/n";
    return 0;
}
//用命名空间限制符访问变量

//Another example:
#include<iostream>
using namespace std;
namespace Cui{
void Love()
{
    cout<<"He love a wonderful girl, and her name is SHILI"<<endl;
}
}
using namespace Cui;
int main()
{
    int a=10;
    cout<<a<<endl;
    Love();
    Cui::Love();//调用方式2
    return 0;
}

What’s more~

The first part operator() is the way to declare the function that is called when an instance of the class is invoked as a function. The second pair of parentheses would contain the actual arguments.

With a return value and arguments this might make a bit more sense:

class Adder{
public:
int operator()(int a, int b){
    //operator() -- this is the "name" of the operator
    //         in this case, it takes two integer arguments.
    return a+b;
}
};
Adder a;
assert( 5==a(2,3) );
解释cppcheck中不同等级的含义,如何限制检查等级enum class Severity : std::uint8_t { /** * No severity (default value). */ none, /** * Programming error. * This indicates severe error like memory leak etc. * The error is certain. */ error, /** * Warning. * Used for dangerous coding style that can cause severe runtime errors. * For example: forgetting to initialize a member variable in a constructor. */ warning, /** * Style warning. * Used for general code cleanup recommendations. Fixing these * will not fix any bugs but will make the code easier to maintain. * For example: redundant code, unreachable code, etc. */ style, /** * Performance warning. * Not an error as is but suboptimal code and fixing it probably leads * to faster performance of the compiled code. */ performance, /** * Portability warning. * This warning indicates the code is not properly portable for * different platforms and bitnesses (32/64 bit). If the code is meant * to compile in different platforms and bitnesses these warnings * should be fixed. */ portability, /** * Checking information. * Information message about the checking (process) itself. These * messages inform about header files not found etc issues that are * not errors in the code but something user needs to know. */ information, /** * Debug message. * Debug-mode message useful for the developers. */ debug, /** * Internal message. * Message will not be shown to the user. * Tracking what checkers is executed, tracking suppressed critical errors, etc. */ internal };
09-24
我在idea已经点击skip test,为啥还出现报错: ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:testCompile (default-testCompile) on project manager-port-mongo: Compilation failure [ERROR] /D:/JavaProjects/omada_sdn_controller/omada_manager/manager-port-mongo/src/test/java/com/tplink/smb/omada/manager/port/mongo/configuration/site/authentication/radiusprofile/radiusserver/RadiusUserPOMapperTest.java:[66,16] 对于RadiusUserPO(java.lang.String,java.lang.String,java.lang.String,int,java.lang.String,java.lang.String,long,long,long,long,int,int,int), 找不到合适的构造器 [ERROR] 构造器 com.tplink.smb.omada.manager.port.mongo.configuration.site.authentication.radiusprofile.radiusserver.RadiusUserPO.RadiusUserPO(java.lang.String,java.lang.String,java.lang.String,java.lang.Integer,java.lang.String,java.lang.String,java.lang.Long,java.lang.Long,java.lang.Long,java.lang.Long,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer)不适用 [ERROR] (实际参数列表和形式参数列表长度不同) [ERROR] 构造器 com.tplink.smb.omada.manager.port.mongo.configuration.site.authentication.radiusprofile.radiusserver.RadiusUserPO.RadiusUserPO()不适用 [ERROR] (实际参数列表和形式参数列表长度不同) [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <args> -rf :manager-port-mongo
11-15
本指南详细阐述基于Python编程语言结合OpenCV计算机视觉库构建实时眼部状态分析系统的技术流程。该系统能够准确识别眼部区域,并对眨眼动作与持续闭眼状态进行判别。OpenCV作为功能强大的图像处理工具库,配合Python简洁的语法特性与丰富的第三方模块支持,为开发此类视觉应用提供了理想环境。 在环境配置阶段,除基础Python运行环境外,还需安装OpenCV核心模块与dlib机器学习库。dlib库内置的HOG(方向梯度直方图)特征检测算法在面部特征定位方面表现卓越。 技术实现包含以下关键环节: - 面部区域检测:采用预训练的Haar级联分类器或HOG特征检测器完成初始人脸定位,为后续眼部分析建立基础坐标系 - 眼部精确定位:基于已识别的人脸区域,运用dlib提供的面部特征点预测模型准确标定双眼位置坐标 - 眼睑轮廓分析:通过OpenCV的轮廓提取算法精确勾勒眼睑边缘形态,为状态判别提供几何特征依据 - 眨眼动作识别:通过连续帧序列分析眼睑开合度变化,建立动态阈值模型判断瞬时闭合动作 - 持续闭眼检测:设定更严格的状态持续时间与闭合程度双重标准,准确识别长时间闭眼行为 - 实时处理架构:构建视频流处理管线,通过帧捕获、特征分析、状态判断的循环流程实现实时监控 完整的技术文档应包含模块化代码实现、依赖库安装指引、参数调优指南及常见问题解决方案。示例代码需具备完整的错误处理机制与性能优化建议,涵盖图像预处理、光照补偿等实际应用中的关键技术点。 掌握该技术体系不仅有助于深入理解计算机视觉原理,更为疲劳驾驶预警、医疗监护等实际应用场景提供了可靠的技术基础。后续优化方向可包括多模态特征融合、深度学习模型集成等进阶研究领域。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值