Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何编写此方法的定义我遇到了一个错误_C++_Function_Class_Header - Fatal编程技术网

C++ 如何编写此方法的定义我遇到了一个错误

C++ 如何编写此方法的定义我遇到了一个错误,c++,function,class,header,C++,Function,Class,Header,提前谢谢 我正在尝试为该方法编写定义 Customer* getMemberFromID(std::string); 这是我写的定义,但我得到了一些错误,即“类存储”中的[error]“Customer”没有命名类型 Store:: Customer* getMemberFromID(std::string id) { for(int i = 0; i < members.size(); i++) { Customer* c = members.at(i)

提前谢谢 我正在尝试为该方法编写定义

Customer* getMemberFromID(std::string);
这是我写的定义,但我得到了一些错误,即“类存储”中的[error]“Customer”没有命名类型

Store:: Customer* getMemberFromID(std::string id)
{
    for(int i = 0; i < members.size(); i++)
    {
        Customer* c = members.at(i);
        if(c->getAccountID() == id)
        {

            return c;
        }
    }
    return NULL;
}
Store::Customer*getMemberFromID(std::string id)
{
对于(int i=0;igetAccountID()==id)
{
返回c;
}
}
返回NULL;
}
试试看

很难说是完整的(你真的应该提供),但我猜
getMemberFromId
Store
的成员函数,但是
Customer
不是
Store
的成员,你只是被命名规则弄糊涂了

注意:我将
(std::string id)
替换为
(std::string const&id)
,以避免在不需要字符串时额外复制它

然后您可以使用标准算法:

试一试

很难说是完整的(你真的应该提供),但我猜
getMemberFromId
Store
的成员函数,但是
Customer
不是
Store
的成员,你只是被命名规则弄糊涂了

注意:我将
(std::string id)
替换为
(std::string const&id)
,以避免在不需要字符串时额外复制它

然后您可以使用标准算法:


函数定义规则

<return type>  <class name> :: <function name><Arguments>

函数定义规则

<return type>  <class name> :: <function name><Arguments>

你的函数原型是错误的

改变

Store:: Customer* getMemberFromID(std::string id)


你的函数原型是错误的

改变

Store:: Customer* getMemberFromID(std::string id)


谢谢你的帮助,我试过了,但是我现在收到了一个错误,说id not captureI解决了这个错误,现在又出现了另一个错误,说“find_if(std::vector::iterator,std::vector::iterator,Store::getMemberFromID(std::string)::”@user1210000你有没有
\35;包括
?(对不起,我应该说得很清楚,我想从链接中可以清楚地看到。)从您的错误来看,
成员是一个
std::vector
,但在您最初的示例中,它显然是
客户*
的容器。你确定你为
find_if
的前两个参数使用了正确的容器吗?我会将链接连同完整的程序一起发送给你,代码现在有很多更改,你已经提到了感谢我尝试的帮助,但是我现在收到一个错误,说id not capture我解决了这个错误,现在又出现了另一个错误,说
[错误]调用“find_if(std::vector::iterator,std::vector::iterator,Store::getMemberFromID(std::string)::)”时没有匹配的函数。
@user1210000您是否
\include
?(对不起,我应该明确说明这一点,我想从链接中可以看清楚).从您的错误来看,
成员是一个
std::vector
,但在您最初的示例中,它显然是
客户*
的某个容器。您确定为
find\u if
的前两个参数使用了正确的容器吗?我会将链接发送给您,并提供完整的程序,该代码现在有许多更改,您已经告诉我了提及
Store:: Customer* getMemberFromID(std::string id)
Customer* store::getMemberFromID(std::string id)