char* misinterpreted as int*

This is a discussion on char* misinterpreted as int* within the C++ Programming forums, part of the General Programming Boards category; Hi everybody! I'm using Visual Studio 2005 and don't know how to solve this problem. Till now, everything worked just ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    6

    Question char* misinterpreted as int*

    Hi everybody!
    I'm using Visual Studio 2005 and don't know how to solve this problem. Till now, everything worked just fine, included all the necessary libs, headers and so on.

    But there is the problem:
    I have to implement a class ColorSpaces with static member functions, which manipulates a buffer from the class MSImage and returns it.

    ColorSpaces.h looks like this:
    Code:
    class ColorSpaces
    {
    public:
    	ColorSpaces();
    	virtual ~ColorSpaces(void);
    
    	// returns a buffer, where the L,a,b values of a given MSImage are stored
    	static char* calculateLab(MSImage* image);
    	static char* calculateLuv(MSImage* image);
    	static char* calculateRG(MSImage* image);
    
    };
    ColorSpaces.cpp does nothing much till now, but looks like this:
    Code:
    ColorSpaces::ColorSpaces()
    {
    }
    
    // ----------------------------------------------------------------------------
    ColorSpaces::~ColorSpaces(void)
    {
    }
    
    char* ColorSpaces::calculateLab(MSImage* image)
    {
    //	cout << image->data3D << endl;
    }
    
    char* ColorSpaces::calculateLuv(MSImage* image)
    {
    
    }
    
    char* ColorSpaces::calculateRG(MSImage* image)
    {
    
    }
    I'm calling calculateLab from main:
    Code:
    MSImage msimage(str,false); // reads image and safes it in unsigned char*** data3D
    ColorSpaces::calculateLab(&msimage);

    Problem 1:

    Why I get this error message?
    Code:
    error LNK2001: unresolved external symbol "public: static char * __cdecl ColorSpaces::calculateLab(class MSImage *)" (?calculateLab@ColorSpaces@@SAPADPAVMSImage@@@Z)
    Problem 2:
    When I'm hoovering over calculateLab with my mouse, tooltip says:
    Code:
    int* ColorSpaces::calculateLab(void);
    Why is that?

    Can anybody help me pleeze? Would be much appreciated. Thx

    Bye
    Adamn

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    can you post the complete code for both files?

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    6
    Quote Originally Posted by nadroj View Post
    can you post the complete code for both files?
    This is the complete code for ColorSpaces.cpp and ColorSpaces.h .... to post all the other stuff, i think its too complicated.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i was just wondering about the includes.
    the error looks like either something isnt included that needs to be or it cant find the proper .lib file that MSImage needs, is my guess.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    6
    Quote Originally Posted by nadroj View Post
    i was just wondering about the includes.
    the error looks like either something isnt included that needs to be or it cant find the proper .lib file that MSImage needs, is my guess.
    #include "ColorSpaces.h" is inserted in main.cpp, ColorSpaces.cpp and in MSImage.h.
    #include "MSImage.h" is inserted in MSImage.cpp

    The strange this is, everything just worked fine before I inserted the ColorSpaces class. Has this maybe something to do with the static member functions in ColorSpaces?

    And what about this misinterpretation? It should be char* and not int*.

    Thx for trying to help!
    Last edited by Adamn; 09-13-2007 at 12:08 AM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    im not sure.
    but since you have declared it static in the header i would declare it static in the cpp file. also, you are declaring it to return something (a static char*, according to the header), but you arent returning anything. fix those two things, save, compile, then see if it is still showing the wrong return type.

    im off to bed but will check back in the morning.

    edit: this may help http://msdn.microsoft.com/library/de...ml/lnk2001.asp
    Last edited by nadroj; 09-13-2007 at 12:16 AM.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    6
    Quote Originally Posted by nadroj View Post
    im not sure.
    but since you have declared it static in the header i would declare it static in the cpp file. also, you are declaring it to return something (a static char*, according to the header), but you arent returning anything. fix those two things, save, compile, then see if it is still showing the wrong return type.

    im off to bed but will check back in the morning.
    If I declare it as static in the cpp file, it says " 'static' should not be used on member functions defined at file scope" ... so there wasn't the problem.
    And I returned something .... still the same problem!

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    6
    Quote Originally Posted by nadroj View Post
    From msdn:
    Static functions/variables

    Functions declared with the static modifier by definition have file scope. Static variables have the same limitation. Trying to access any static variables from outside of the file in which they are declared can result in a compile error or an unresolved external depending on the specific coding of the source files.
    This seems to be my problem, but there is no solution to this suggested!

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    don't declare it as static...?

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by robwhit View Post
    don't declare it as static...?
    Ehm, this is a static function within a class - and I think the problem is that it's declared static in the header file _AND_ in the .cpp file, which isn't required [and apparently not correct].

    A static class-member can be called outside of the class. [This is quite extensively used in the code where I work...]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Sep 2007
    Posts
    6
    Quote Originally Posted by matsp View Post
    Ehm, this is a static function within a class - and I think the problem is that it's declared static in the header file _AND_ in the .cpp file, which isn't required [and apparently not correct].
    Mats
    It's NOT declared as static in the cpp file. I got the solution now....
    Code:
    class __declspec(dllexport) ColorSpaces
    Thx for all your support!

    Adamn

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