Search code examples
c++opencvstaticdeclaration

Qualified-id in declaration before '=' token


I have two public classes; one static (DesktopOps), one non-static (Args), and I'm trying to initialise the static variables of the static class in main.

The error message I keep getting is:

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);
                                   ^

Here's a 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);
}

Solution

  • I don't really understand what you are trying to do....but static variables must be created in global scope, outside the main function:

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

    But this global Args variable does not make sense....