C++编译器无法识别成员函数和类型
今天是发生奇怪事情的一天...... 有一个愚蠢的 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:错误: '班级 middleware::WFQueueManagerProxy' 有 没有名为“_config”的成员 wfqueue_manager_proxy.cpp:33:错误: '班级 middleware::WFQueueManagerProxy' 有 没有名为“_config”的成员 wfqueue_manager_proxy.cpp:在全局 范围:wfqueue_manager_proxy.cpp:51: 错误:变量或字段 “ConfigureProxy”声明无效 wfqueue_manager_proxy.cpp:51:错误: 未声明“WFProxyConfig” 这个范围
荒谬... 它不识别 typedef,也不识别私有成员...而且,最重要的是...为什么 g++ 不识别试图将其视为变量的成员函数?????????
我已经尝试了一切... PS(对于看过我之前帖子的人):我的虚拟机现在不是原因。我检查并确认没有虚拟硬盘损坏或与其他虚拟内存单元发生冲突。
Today it's the day of strange things....
Got a stupid hpp file and another stupid cpp file trying to implement a stupid class.
Here they are:
// 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
Here the other
// 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) {
}
Somebody please explain me why g++ tells me this:
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
ABSURD...
It does not recognize that typedef and doesn't recognize a private member too... and, more than everything... why does not g++ recognize a member function trying to see it as a variable?????????
I have tried everything...
PS (to who saw my earlier post): my virtual machine now is not the cause. I checked and got confirm that no virtual hard disk is corrupted or in collision with other virtual mem units.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只是一个猜测。难道不应该吗
Just a guess. Shouldn't it be
当我删除 WFProxyConfig 的声明(或更改声明的名称)时,我收到了您遇到的错误。您确定您发布了产生错误的确切代码吗?
I get the error you are getting when I remove the declaration of WFProxyConfig (or change the name declared). Are you sure you posted the exact code that is producing the error?
带有前导下划线的标识符被保留(包括保护以及
_config
)。如果您遇到其中一个问题,我会感到有点惊讶 - 但并不感到惊讶。_config
甚至可能是 g++ 扩展关键字。Identifiers with leading underscores are reserved (include guards as well as
_config
). I'd be a little surprised if one of these is your problem - but not that surprised._config
might even be a g++ extension keyword.好吧,这就是错误......
我还编译了头文件..许多gch都是这样创建的...g++没有更新那些预编译头文件并得到了旧代码...这就是为什么它对我所做的任何更改都漠不关心...抱歉打扰你们。 ..非常感谢您的帮助
OK, this was the error....
I also compiled headers.. many gch were so created.... g++ didn't update those precompiled headers and got an old code... that's why it was indifferent to any change I did... sorry for disturb you guys... thanks a lot for your help