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

时间:2010-11-28 15:04:39

标签: 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:在   构造函数   “中间件:: WFQueueManagerProxy :: WFQueueManagerProxy()”:   wfqueue_manager_proxy.cpp:32:错误:   '类   中间件:: WFQueueManagerProxy'有   没有名为'_config'的成员   wfqueue_manager_proxy.cpp:33:错误:   '类   中间件:: WFQueueManagerProxy'有   没有名为'_config'的成员   wfqueue_manager_proxy.cpp:在全球范围内   范围:wfqueue_manager_proxy.cpp:51:   错误:变量或字段   'ConfigureProxy'声明为void   wfqueue_manager_proxy.cpp:51:错误:   'WFProxyConfig'没有被宣布   这个范围

...荒谬 它不识别typedef并且也不识别私有成员......并且,不仅仅是一切......为什么g ++不能识别成员函数试图将其视为变量?????????

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

4 个答案:

答案 0 :(得分:5)

只是一个猜测。不应该是

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

答案 1 :(得分:1)

当我删除WFProxyConfig声明(或更改声明的名称)时,我收到错误。您确定发布了产生错误的确切代码吗?

答案 2 :(得分:0)

保留带有前导下划线的标识符(包括警卫以及_config)。如果其中一个是您的问题,我会感到有点惊讶 - 但 感到惊讶。

_config甚至可能是g ++扩展关键字。

答案 3 :(得分:0)

好的,这是错误.... 我也编译了标题..许多gch是如此创建的.... g ++没有更新那些预编译的标题并得到一个旧的代码...这就是为什么它对我所做的任何改变都无动于衷...对不起打扰你们。 ..非常感谢你的帮助