今天是奇怪的一天...... 有一个愚蠢的 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/