[英]C++ protected typedef as return value
I'm not sure if this even is possible, but basically i have this pointer typedef that is protected in a class that i share among my threads and i want to make a function that returns a pointer of that typedef. 我不确定这是否可能,但基本上我有这个指针typedef,该指针在我在线程之间共享的类中受保护,并且我想创建一个返回该typedef指针的函数。
I can declare the function in my .h with no problem but the .cpp says it doesn't recognize it. 我可以毫无问题地在.h中声明该函数,但.cpp表示无法识别该函数。 I can also use my typedef within a function.
我也可以在函数中使用typedef。 Only thing as i said i can't do is have it as a return value.
正如我所说,我做不到的只有它作为返回值。
I doubt you guys have to even see the code but i'm posting it just to make it complete. 我怀疑你们甚至必须看到代码,但我只是为了使其完整而发布。
Shared header: 共享头:
#pragma once
class CR
{
public:
private:
public:
int c_outPut(std::string &output);
protected:
typedef std::unordered_map<in_addr, SOCKET>::const_iterator cit;
};
Short version of the other .h 其他.h的简短版本
#pragma once
#include "commonRec.h"
#include <unordered_map>
#include <WinSock2.h>
#include <iterator>
class CH : CR
{
std::string sendToCon(cit &const_it, const std::string &command);
cit findHost(std::string &searchHost);
};
.cpp function declaration - error "cit is undeclared identifier" .cpp函数声明-错误“ cit是未声明的标识符”
cit CC::_translateCommand(string &command)
{
}
I can also use my typedef within a function.
我也可以在函数中使用typedef。
The key word here is within . 这里的关键词是内 。
Only thing as i said i can't do is have it as a return value.
正如我所说,我做不到的只有它作为返回值。
Your return type declaration is outside of the scope of the function. 您的返回类型声明不在函数范围内。 Outside of the scope of
CR
, cit
can only refer to ::cit
. 在
CR
范围之外, cit
只能引用::cit
。 But you did not define the type ::cit
; 但是您没有定义类型
::cit
; you defined CR::cit
. 您定义了
CR::cit
。 So, when you're outside the scope of CR
, such as when you declare a member function out-of-line, you must resolve the scope explicitly: 因此,当您超出
CR
的范围时,例如当您离线声明成员函数时,必须显式地解决该范围:
CR::cit CC::_translateCommand(string &command)
A trailing return type declaration is within the scope of the function, so if you used that, then you wouldn't need explicit resolution: 尾随返回类型声明在函数的范围内,因此,如果使用了该声明,则不需要显式解析:
auto CC::_translateCommand(string &command) -> cit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.