Error with LB_ADDSTRING..

This is a discussion on Error with LB_ADDSTRING.. within the Windows Programming forums, part of the Platform Specific Boards category; Why do I get this error: 78 wnd_mng.cpp initialization to `const char' from `const char *' lacks a cast 87 ...

  1. #1
    BubbleMan
    Guest

    Post Error with LB_ADDSTRING..

    Why do I get this error:

    78 wnd_mng.cpp
    initialization to `const char' from `const char *' lacks a cast
    87 wnd_mng.cpp
    jump to case label

    and the same thing again??

  2. #2
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    Can you illustrate your problem with some relevant code?
    Greetings.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    I guess your code looks something like this:

    switch(something)
    {
    case x:
    const char A = "text";
    ...
    break;
    case y:
    ...
    break;
    }

    To solve the problems, put brackets around the 'case x' statements. Also add a '*' before 'A' in i order to make it a pointer. Storing a string pointer into a signed byte isn't good.

    This is how if should look like:

    switch(something)
    {
    case x:
    {
    const char *A = "text";
    ...
    }
    break;
    case y:
    ...
    break;
    }
    // Gliptic

  4. #4
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    It seems you are trying to define which text is stored into A in different cases: In this case I think you can't use a const value.
    (a const value is loaded into process memory space as soon as your program is loaded in memory, and this piece of memory is blocked against writing while your program runs)

    If I were you I would try to modify the code as follows:

    int iLen = 0;
    char * A = NULL ;

    switch(something)
    {
    case x:
    iLen = strlen("some text") + 1;
    A = new char[iLen];
    strcpy(A,"some text");
    //use the value of A

    delete [] A;
    case y:
    iLen = ...
    A = new char[iLen];
    //...

    delete [] A;
    //...
    }
    Greetings.

Popular pages Recent additions subscribe to a feed

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