Вложенный проход по ссылке - PullRequest
1 голос
/ 19 августа 2011

Мне нужно иметь вложенный проход по ссылке.

ИЗМЕНЕНО ДЛЯ ВКЛЮЧЕНИЯ АКТУАЛЬНОГО КОДА

Точная ошибка:

нетФункция соответствия для вызова 'CLItem :: getValue (std :: string * &)'

Полная ошибка:

App/CycCmdLine.cpp: In member function ‘std::string CycCmdLine::getEnvironment()’:
App/CycCmdLine.cpp:245: error: no matching function for call to ‘CycCmdLine::getValue(const char [16], std::string&)’
./../CmdLine/CmdLine.h: In member function ‘bool CmdLine::getValue(std::string, T&) [with T = std::string*]’:
App/CycCmdLine.cpp:384:   instantiated from here
./../CmdLine/CmdLine.h:237: error: no matching function for call to ‘CLItem::getValue(std::string*&)’
./../CmdLine/CmdLine.h:145: note: candidates are: bool CLItem::getValue(bool&)
./../CmdLine/CmdLine.h:146: note:                 bool CLItem::getValue(std::string&)
./../CmdLine/CmdLine.h:147: note:                 bool CLItem::getValue(long unsigned int&)
./../CmdLine/CmdLine.h:148: note:                 bool CLItem::getValue(std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)
./../CmdLine/CmdLine.h:149: note:                 bool CLItem::getValue(std::list<std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&)

Обновленный код:

// initial caller
string CycCmdLine::getEnvironment()
{
    string sRet="";
    do
    {     
        if(hasLogFile())
            {
                string sLogFile="";
                getValue(CYCCMD_CMDSTR_LOGFILE, sLogFile);
                sRet+="\n  -Profiler logfile: "+sLogFile;
            }
    }while(false);
    return(sRet);
}

// CmdLine::getValue function definition (this is in the header file, as a template should be)
template <typename T>
bool CmdLine::getValue(string sName, T &tValue)
{
    bool bRet=false;
    do
    {
    // try to get the iterator
    bool bExists;
    map<string, CLItem*>::iterator itItr;
    bExists=getMapElement(sName, itItr);

        // go ahead and return the value
        if(!itItr->second->getValue(tValue)) { break; }
        bRet=true;
    }while(false);
    return(bRet);
}

bool CLItem::getValue(string& sValue)
{
    bool bRet=false;
    do
    {
        // is this the correct type?
        if(!isType(CLType_STRING)) { break; }

        // return the value
        sValue=m_sValue;
        bRet=true;
    }while(false);
    return(bRet);
}

Ответы [ 2 ]

3 голосов
/ 19 августа 2011

Если мы посмотрим на эту часть сообщения

./../CmdLine/CmdLine.h: In member function ‘bool CmdLine::getValue(std::string, T&) [with T = std::string*]’:
App/CycCmdLine.cpp:384:   instantiated from here
./../CmdLine/CmdLine.h:237: error: no matching function for call to ‘CLItem::getValue(std::string*&)’

Кажется, говорят, что на App/CycCmdLine.cpp:384 вы вызываете getValue с T, являющимся std::string*. Это приводит к тому, что шаблон пытается вызвать функцию, которая не существует.

Начни исследовать эту строку 384!

2 голосов
/ 19 августа 2011

Вы можете воспроизвести эту ошибку с помощью этого кода.

#include <string>

struct X
{
    void foo(std::string& n)
    {
    }

    void bar()
    {
       std::string* s;
       foo(s);
    }
};


prog.cpp: In member function ‘void X::bar()’:
prog.cpp:12: error: no matching function for call to ‘X::foo(std::string*&)’
prog.cpp:5: note: candidates are: void X::foo(std::string&)

Предлагаемый символ ссылки не очень значим.Вы действительно пытаетесь передать указатель, где ожидается значение, и компилятор угадывает, как может выглядеть подходящая функция для этого вызова.(Это, вероятно, означает, что вы передаете lvalue, поэтому функция может принимать его по ссылке.)

Также обратите внимание, что в нем перечислены кандидаты, функции с тем же именем, но с неподходящими типами параметров.


Теперь, когда вы разместили реальный код, возможно, проверьте, какой тип шаблона используется в вашем ошибочном экземпляре (об этом должно упоминаться и в сообщении об ошибке).Вы также опубликовали сообщения об ошибках:

App/CycCmdLine.cpp: In member function ‘std::string CycCmdLine::getEnvironment()’:
App/CycCmdLine.cpp:245: error: no matching function for call to ‘CycCmdLine::getValue(const char [16], std::string&)’

Это первая ошибка.Перевод: класс CycCmdLine не имеет функции-члена getValue (и при этом нет глобальной функции с таким именем).Функция с таким именем является членом CmdLine.

./../CmdLine/CmdLine.h: In member function ‘bool CmdLine::getValue(std::string, T&) [with T = std::string*]’:
App/CycCmdLine.cpp:384:   instantiated from here
./../CmdLine/CmdLine.h:237: error: no matching function for call to ‘CLItem::getValue(std::string*&)’

Это вторая ошибка, о которой вы спрашиваете.Вы передаете указатель на строку в строке 384 CycCmdLine.cpp (которая находится в другом месте, чем вы думали).

...