获得invalig使用C++非静态数据成员的错误

问题描述:

哪些错误与下面的代码,即使我已经正确使用变量file_op非静态变量,也宣告正确我得到下面的错误....获得invalig使用C++非静态数据成员的错误

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; 
} 

错误:

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

你的方法write_params是类ILV_file_operations::Response的一员,但它试图访问类ILV_file_operations的非静态成员变量没有对象。
首先,您需要类ILV_file_operations的对象来访问其成员,或者该成员必须是static
但是,你仍然可以不访问成员变量,因为它们是private,并且你的内部类不能自动访问它们外部类的成员变量。