0

Whats wrong with the code below even if I have used the variable file_op properly as non static variable and also declared properly I am getting below error....

class ILV_file_operations: public ILV_command
{
private:
    /**
     * \copydoc ILV_command::ILV_command_request
     */
    class Request: public ILV_command_request<ILV_file_operations>
    {
        friend class ILV_file_operations;
        // New format parameters
        uint32_t file_op;
        std::string file_path;
        std::string file_read_data;
        uint8_t request_status; //!<  Response status
    public:
        explicit Request(ILV_file_operations& parent_ref);
        ~Request();

        /**
         * \brief This is method to read the parameters received in the request.
         * \return
         * \arg \c Length: Length of the request data read
         */
        uint32_t read_params();
    };

    class Response: public ILV_command_response<ILV_file_operations>
    {
        friend class ILV_file_operations;
        //New parameter
        std::list<Sub_ILV> param_ILV; ///< Parameter ILV

        // Old format parameters
        std::string file_write_data; ///< Serial number
        uint8_t response_status; //!<  Response status
    public:
        explicit Response(ILV_file_operations& parent_ref);
        ~Response();

        /**
         * \brief This is method to calculate the length of the response to be sent.
         * \return
         * \arg \c Length: Length of the response data
         */
        uint32_t calculate_length();
        /**
         * \brief This is method to write the parameters in the response.
         * \return
         * \arg \c Length: Length of the response data written
         */
        uint32_t write_params();
    };

    Response resp_data; ///< Response data object
    Request req_data; ///< Request data object

public:

    /**
     * \copydoc ILV_command::ILV_command
     */
    explicit ILV_file_operations(boost::shared_ptr<Protocol>& prtcl);
    /**
     */
    virtual ~ILV_file_operations();

    void process();
    uint32_t read_packet();
    uint32_t write_packet();
};


uint32_t ILV_file_operations::Response::write_params()
{
    uint32_t ret_val = 0;

    if (((int)req_data.file_op) == ((int)file_operation_type::write))
    {
        ret_val += parent.cmd_prot->write_string(file_write_data);
    }
    return ret_val;
}

Error :

| Compiling core_app/src-libs/libCommand_manager/src/ILV_commands/ILV_file_operations.cpp ...
| In file included from core_app/src-libs/libCommand_manager/src/ILV_commands/ILV_file_operations.cpp:11:0:
| ../include/ILV_commands/ILV_file_operations.h: In member function 'virtual uint32_t Dist_cmd_processor::ILV_file_operations::Response::write_params()':
| ../include/ILV_commands/ILV_file_operations.h:82:13: error: invalid use of non-static data member 'Dist_cmd_processor::ILV_file_operations::req_data'
|      Request req_data; ///< Request data object
|              ^
| /home/sagar/morpho/MASigma_Firmware_REV_1.0.10/src-ma5g/core_app/src-libs/libCommand_manager/src/ILV_commands/ILV_file_operations.cpp:84:15: error: from this location
|      if (((int)req_data.file_op) == ((int)file_operation_type::write))
|                ^

1 Answer 1

2

Your method write_params is a member of the class ILV_file_operations::Response, but it tries to access a non-static member variable of the class ILV_file_operations without an object.
First, you would either need an object of the class ILV_file_operations to access its members, or the member would have to be static.
But then you could still not access the member variables because they are private, and your inner classes don't get automatic access to the member variables of their outer class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.