Thread: Error in passing arguments

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    15

    Error in passing arguments

    I have defined an abstract class so I must use reference to that class... I also use a list with that type... the problem is when I intent to use the iterator as an argument to a function.
    This is the snap:
    Code:
     void sustituir(CTermino *&termino)
          //Dado un termino, le aplica la sustituciÃģn y lo entrega modificacdo
          {
              Parser parser;
            if (!(invalida) && !(esSustitucionVacia()))
            {
             //Solicito la lista de parametros del termino, para atenderlo en caso de que sea una funcion
             list<CTermino> * listaParametros = termino->getListaParametros();
             list<CTermino>::iterator it = listaParametros->begin();
             
    
             //Dependiendo del tipo de termino que sea, lo sustituyo         
             switch (!(termino->perteneceVariable(termino) || parser.esConstante(termino->getSimbolo()))) {
                case false:
                          if ( mapaReemplazos.find(termino->getSimbolo()) != mapaReemplazos.end())
                          { 
                            termino = (mapaReemplazos[termino->getSimbolo()]).second;
                          }           
                    break;
                case true:
                          while (it != listaParametros->end()) 
                          {
                            sustituir (*it);
                         
                            it++;  
                          }
                          termino->setListaParametros(*listaParametros);
                      break;     
                default: ;
                }
             delete listaParametros;             
            }
          }
    When I compile I got:
    error: no matching function for call to 'CSustitucion::sustituir(CTermino&)'
    note: candidates are: void CSustitucion::sustituir(CTermino*&)

    Is it possible to do what I intent to do? What should I do in order to correct such compile error?

    Thanks in advance!!!!!

  2. #2
    Registered User
    Join Date
    Dec 2009
    Location
    /dev/pts/0
    Posts
    29
    error: no matching function for call to 'CSustitucion::sustituir(CTermino&)'
    note: candidates are: void CSustitucion::sustituir(CTermino*&)
    That error message means that you don't have a function called CSustitucion::sustituir that takes a CTermino reference as a parameter. Instead, it would appear you're instead passing a reference to a pointer? . . . can I see the code for CSustitucion::sustituir()?
    -- strange

    There is no Darkness in Eternity
    Only Light too dim for us to see

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    15
    Thatīs the code... itīs recursive function.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perhaps you should have called it as:
    Code:
    sustituir(&*it);
    since you need to pass a pointer according to the function signature.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    15
    I have also tried that alternative as I did in another case... but I donīt know why it doesnīt work... I intented to do a cast to, but I couldnīt solve the issue.

  6. #6
    Registered User
    Join Date
    Dec 2009
    Location
    /dev/pts/0
    Posts
    29
    *sigh*. I'm sorry, I'm very tired at the moment. I would concur with laserlight, that you need to pass it a pointer, since that is what the implementation specifies.

    Out of curiosity, why are you passing a reference to a pointer? Unless you're changing what the pointer references, it's slightly redundant . . . I think . . .
    -- strange

    There is no Darkness in Eternity
    Only Light too dim for us to see

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    15
    CTermino is an abstract class, thatīs what I use CTermino *

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by tommantonela
    I have also tried that alternative as I did in another case... but I donīt know why it doesnīt work... I intented to do a cast to, but I couldnīt solve the issue.
    Oh yes, that would not work, and that is directly related to what strange found strange.

    The problem is that since the parameter is a non-const reference, one must pass a modifiable lvalue to it. However the result of the address-of operator is an rvalue.

    You appear to need to pass the pointer by reference because of this statement:
    Code:
    termino = (mapaReemplazos[termino->getSimbolo()]).second;
    I have no understanding of what your code actually does, but perhaps you should pass the pointer by value and change the above statement to copy a CTermino object:
    Code:
    *termino = *(mapaReemplazos[termino->getSimbolo()]).second;
    By the way, please translate your code to English before posting. It makes it easier for most of us to understand your code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    By the way, please translate your code to English before posting. It makes it easier for most of us to understand your code.
    Seconded. I cannot tell from the code why you need to pass in *&CTermino or why single indirection (just a simple pointer) would not work just as well.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    switching on a bool is truly weird. Especially the default case for neither true or false. A Tri-bool perhaps?
    Most people use an if-else-statement.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    Registered User
    Join Date
    Dec 2009
    Posts
    15
    Sorry for my Spanish Code!!! That function is used in order to solve a part of problems related with First Order Logic... to check the satisfiability of a set of clauses...
    The switch is not the problem even though is not the perfect solution...
    laserligth, I did what you said but the problem continuos :S

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I am a little puzzled though. If CTermino is an abstract base class, then how can you have a list<CTermino>?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Quote Originally Posted by strange View Post
    That error message means that you don't have a function called CSustitucion::sustituir that takes a CTermino reference as a parameter. Instead, it would appear you're instead passing a reference to a pointer? . . . can I see the code for CSustitucion::sustituir()?

    Unless I am overlooking/simplifying this but the error alone, really, points out the problem. . It specifies the possible candidate that matches your declaration, the compiler is trying to guess on your intentions here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Arguments
    By bolivartech in forum C Programming
    Replies: 13
    Last Post: 10-15-2009, 01:31 PM
  2. Passing arguments
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2009, 01:14 PM
  3. Passing arguments.
    By omnificient in forum C Programming
    Replies: 3
    Last Post: 05-28-2008, 02:41 PM
  4. Passing arguments between functions
    By Wiretron in forum C Programming
    Replies: 4
    Last Post: 05-17-2006, 04:59 PM
  5. passing arguments
    By Baard in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2003, 08:10 AM