C++ 编译器无法识别成员函数和类型

标签 c++ class compiler-errors

今天是奇怪的一天...... 有一个愚蠢的 hpp 文件和另一个愚蠢的 cpp 文件试图实现一个愚蠢的类。 他们在这里:

// HPP

#ifndef _WFQUEUE_MANAGER_PROXY_HPP_
#define _WFQUEUE_MANAGER_PROXY_HPP_

#include <iostream>
#include <string>

#include "workflow.hpp"
#include "wfqueue.hpp"

//-----------------------------------------------------------------------------
// Enum, struct, aliases
namespace middleware {
typedef struct {
    std::string proxy_ipaddr; /* IP address to manager */
    std::string proxy_port; /* Port to manager */
} WFProxyConfig;
}
//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*!
 * This class provides network interface to access the workflow queue. It is
 * important to notice that constructor is private in order to let a factory
 * perform such a work.
 */
class WFQueueManagerProxy : public WFQueue {
    /*!
     * To let factory build properly this object, we provide access to every
     * part of it.
     */
    friend class WFQueueProxyFactory;
private:
    /*!
     * Privately constructs the object. Default configuration with loopback
     * address and invalid port.
     */
    WFQueueManagerProxy();
public:
    /*!
     * Destructor
     */
    ~WFQueueManagerProxy();
    /*!
     * Enqueues a workflow.
     */
    void enqueue(const Workflow& workflow);
    /*!
     * Dequeues a workflow.
     */
    const Workflow& dequeue();
private:
    /*!
     * Privately constructs the object. Assigning configuration.
     */
    void ConfigureProxy(WFProxyConfig conf);
    /*!
     * Parameters for proxy.
     */
    WFProxyConfig _config;
}; /* WFQueueManagerProxy */
} /* middleware */

#endif

其他的

// CPP

#include "wfqueue_manager_proxy.hpp"

using namespace middleware;

//-----------------------------------------------------------------------------
// Constructors and destructor
/* Private constructor */
WFQueueManagerProxy::WFQueueManagerProxy() {
    (this->_config).proxy_ipaddr = "127.0.0.1";
    (this->_config).proxy_port = "0";
}
/* Destructor */
WFQueueManagerProxy::~WFQueueManagerProxy() {

}
//-----------------------------------------------------------------------------
// Public members
/* Enqueue */
void WFQueueManagerProxy::enqueue(const Workflow& workflow) {

}
/* Dequeue */
const Workflow& WFQueueManagerProxy::dequeue() {

}
//-----------------------------------------------------------------------------
// Private members
void WFQueueManagerProxy::ConfigureProxy(WFProxyConfig conf) {

}

有人请解释为什么 g++ 告诉我这个:

wfqueue_manager_proxy.cpp: In constructor ‘middleware::WFQueueManagerProxy::WFQueueManagerProxy()’: wfqueue_manager_proxy.cpp:32: error: ‘class middleware::WFQueueManagerProxy’ has no member named ‘_config’ wfqueue_manager_proxy.cpp:33: error: ‘class middleware::WFQueueManagerProxy’ has no member named ‘_config’ wfqueue_manager_proxy.cpp: At global scope: wfqueue_manager_proxy.cpp:51: error: variable or field ‘ConfigureProxy’ declared void wfqueue_manager_proxy.cpp:51: error: ‘WFProxyConfig’ was not declared in this scope

荒谬... 它不识别 typedef,也不识别私有(private)成员……而且,最重要的是……为什么 g++ 不识别试图将其视为变量的成员函数????????

我都试过了... PS(致谁看过我之前的帖子):我的虚拟机现在不是这个原因。我检查并确认没有虚拟硬盘损坏或与其他虚拟内存单元冲突。

最佳答案

只是猜测。不应该是吗

WFQueueManagerProxy::WFQueueManagerProxy() { 
    (this->_config).proxy_ipaddr = "127.0.0.1"; 
    (this->_config).proxy_port = "0"; 
} 

关于C++ 编译器无法识别成员函数和类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4297391/

相关文章:

c++ - boost::ptr_vector 是如何深拷贝底层对象的?

c++ - Windows.h - 焦点进入文本输入时的通知

C++:调用模板类的非模板函数

c++ - 重载运算符时 C++ 代码出错

c#类同时实现和继承

haskell - 如何在 Haskell 中创建 Latex Providecommand 的类似物?

c++ - 在mfc中如何实现可停靠对话框?

c++ - 如何在嵌套类中重载 << 运算符

assembly - 尝试在汇编中编译功能

c++ - 如何修复 <function-style-cast> 错误 : Cannot convert from 'initializer list' to asdendingCompare<W>(template functor)