Thread: Error Cannot Convert Parameter 1

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Error Cannot Convert Parameter 1

    I'm working on my own version of corewars and I've come to a halt. I get this error... list:

    Code:
    D:\Programs\Projects\Corewars\main.cpp(19) : error C2446: '==' : no conversion from 'char *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Programs\Projects\Corewars\main.cpp(19) : error C2040: '==' : 'int' differs in levels of indirection from 'char [3]'
    D:\Programs\Projects\Corewars\main.cpp(19) : error C2446: '!=' : no conversion from 'char *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Programs\Projects\Corewars\main.cpp(19) : error C2040: '!=' : 'int' differs in levels of indirection from 'char [3]'
    D:\Programs\Projects\Corewars\main.cpp(24) : error C2446: '!=' : no conversion from 'char *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Programs\Projects\Corewars\main.cpp(24) : error C2040: '!=' : 'int' differs in levels of indirection from 'char [3]'
    D:\Programs\Projects\Corewars\main.cpp(24) : error C2446: '==' : no conversion from 'char *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Programs\Projects\Corewars\main.cpp(24) : error C2040: '==' : 'int' differs in levels of indirection from 'char [3]'
    D:\Programs\Projects\Corewars\main.cpp(43) : error C2664: 'class std::basic_istream<char,struct std::char_traits<char> > &__thiscall std::basic_istream<char,struct std::char_traits<char> >::get(char &)' : cannot convert parameter 1 from 'char *' to 
    'char &'
            A reference that is not to 'const' cannot be bound to a non-lvalue
    Edit: the newest code is in the next page.
    Last edited by drdroid; 07-31-2003 at 02:44 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >else if(first[lp]=="/0" && second[lp]!="/0")
    String literals and char literals are not the same. The escape character is \, not /.

    >else if(first[lp]!="/0" && second[lp]=="/0")
    String literals and char literals are not the same. The escape character is \, not /.
    My best code is written with the delete key.

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    Yah I tried changing that a while ago, though I changed it back. It doesn't do anything for the error messages.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Code:
    else if(first[lp]=="/0" && second[lp]!="/0")
    should probably be
    Code:
    else if(first[lp]=='\0' && second[lp]!='\0')
    Not sure if
    Code:
    data.get(*program[lp]);
    is correct...

    Not sure I understand why you need a for loop in charchech() ..

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    Theres a loop because I'm doing it letter by letter. The loop only continues if each character is the same.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    But you have break; inside all of your if's so it will only run through your loop once, hence a bit meaningless.

  7. #7
    drdoidhere
    Guest

    BAH!!!

    I'm trying to make my own function instead of strcmp. That's the entire point of making that function!

  8. #8
    droidhere
    Guest
    explain more specifically what's wrong

  9. #9
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    what's wrong with this though?

    Code:
    data.get(*program[lp]);
    i tried data.get(&program[lp]) which is what I thought it had to be, and it came up with an error, no error came up with the *. I don't understand what you mean by uninitialized memory.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    You really should set your pointers to zero
    Code:
    char * program[30] = {0};
    The problem with
    Code:
    data.get(*program[lp]);
    is that you have not allocated any space for the pointers. You have only set aside memory to an array of pointers.

    You probably need to do something like
    Code:
    for(int lp=0;lp!=30;lp++)
    {
      program[lp] = new char[15]; 
      data.get(*program[lp]);
      cout << *program[lp] << endl;
      // more code
    }
    Now the address stored in program[] will pointer to a memory space that can hold 15 char's. I picked the number 15 randomly btw.

  11. #11
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    program[lp] is a pointer to a character (and the pointer points to nothing, e.g. it's a random address in memory)

    *program[lp] is the value of the character at that unknown address


    char * program[30]; is an array of character pointers, but none of them point to actual strings. They just hold random memory locations. There are no strings, nor is there memory set aside for the strings.

  12. #12
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ok...

    ok... so what i did now was

    Code:
    char* programs[30];
    char proglist[30];
    then in main i put:
    Code:
    for(int lp=0;lp!=30;lp++)
    	{
    		programs[lp]=&proglist[lp];
    		data.get(*programs[lp]);
    		if(charcheck(programs[lp]," ")==true)
    		{
    			strcpy(programs[lp],"EMPTY SLOT");
    		}
    	}

  13. #13
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ,,,

    the problem now is that i have to cast the variables... or so it says in the errors:

    Code:
    D:\Programs\Projects\Corewars\main.cpp(20) : error C2446: '==' : no conversion from 'char *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    (just one of the errors)

    i dun know where it's trying to convert from a char to an int though.

  14. #14
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    nm... i never knew there was a difference between ' and "

  15. #15
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    now though, theres an error:

    Code:
    D:\Programs\Projects\Corewars\main.cpp(50) : error C2664: 'charcheck' : cannot convert parameter 1 from 'char *[21]' to 'char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    i've tried making char* first to char* first[21], but that doesn't make a difference. btw, here's the new code.
    Last edited by drdroid; 08-01-2003 at 06:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-08-2008, 06:31 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM