cannot convert parameter 1 from 'unsigned char *' to 'const unsigned char *&'

This is a discussion on cannot convert parameter 1 from 'unsigned char *' to 'const unsigned char *&' within the C++ Programming forums, part of the General Programming Boards category; why not!?! >_<...

  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839

    cannot convert parameter 1 from 'unsigned char *' to 'const unsigned char *&'

    why not!?!

    >_<

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    here is the original context of the issue:
    Code:
    foo(const unsigned char*& data)
    {
    // do something
    }
    
    void bar(unsigned char* data)
    {
      foo(data);  
    }


    this also demonstrates the problem:

    Code:
    unsigned char* f;
    
    const unsigned char*& crf = f;
    //seemingly spurious error msg: "Conversion loses qualifiers"
    oddly though, this does not generate errors:

    Code:
    void foo(const unsigned char*& data)
    {
    // do something
    }
    
    void bar(unsigned char* data)
    {
      const unsigned char* temp = data;
      foo(temp);  
    }
    am i overlooking something here or is this a compiler error?

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code would be nice. [Edit: Thank you]

    Code:
    void foo(const unsigned char*& )
    {
    }
    
    int main()
    {
        unsigned char* p;
        foo(p);
    }
    If I'm not mistaken, the reference here is non-const. You can only bind arguments to non-const references if they are the same type (and not temporary), but unsigned char* and const unsigned char* are not the same type.

    Compare with
    Code:
    void foo(const unsigned char* const&);
    Last edited by anon; 10-06-2009 at 10:39 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why can't my perceptron learn correctly?
    By yann in forum C Programming
    Replies: 25
    Last Post: 10-15-2010, 01:26 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 03:49 PM
  4. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 12:57 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21