c++ - '=' token 之前声明中的 qualified-id

标签 c++ opencv static declaration

我有两个公开课;一个静态 (DesktopOps),一个非静态 (Args),我正在尝试初始化 main 中静态类的静态变量。

我不断收到的错误信息是:

main.cpp:25: error: qualified-id in declaration before '=' token
     Point DesktopOps::window_coords = Point(arg.topleft_x, arg.topleft_y);
                                     ^
main.cpp:26: error: qualified-id in declaration before '=' token
     Point DesktopOps::window_dims = Point(arg.width, arg.height);
                                   ^

这是一个 MWE:

#include <opencv2/opencv.hpp>

using namespace cv;

struct Args{
    int topleft_x, topleft_y, width, height;

    Args(){
        topleft_x = topleft_y = width = height = -1;
    }
};


struct DesktopOps {
    static Point window_coords;
    static Point window_dims;

};



int main(){
    Args arg();

    Point DesktopOps::window_coords = Point(arg.topleft_x, arg.topleft_y);
    Point DesktopOps::window_dims = Point(arg.width, arg.height);
}

最佳答案

我真的不明白你想做什么....但是静态变量必须在全局范围内,在主函数之外创建:

Args arg;
Point DesktopOps::window_coords = Point(arg.topleft_x, arg.topleft_y);
Point DesktopOps::window_dims = Point(arg.width, arg.height);

int main(){

}

但是这个全局的Args变量没有意义....

关于c++ - '=' token 之前声明中的 qualified-id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26454099/

相关文章:

c++ - 将图像划分为包含对象的框

android - 需要 android 的 openCv 库

c++ - 使用 opencv 和 C++ 的链接器问题 - Undefined Reference

iphone - iOS NSKeyedUnarchiver 使用静态库时出错

java - Spring Autowiring 静态接口(interface)类

c++ - 为什么 jIndent 破坏了我的 C++ 语法?

c++ - 什么是 "MFC Dialog Extension"? (Windows/C++新手-Linux背景)

c++ - ld : library not found for -lX11

opencv - 图像处理中的 anchor

C静态内联函数重定义规则