CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: void pointer to type

    The best way would be to create template function and \ or set of overloaded functions for logging purposes:

    Code:
    #include <iostream>
    #include <string>
    
    template <typename T>
    void WriteLog(const std::string &sMsg, T val)
    {
    	std::cout << sMsg << val << std::endl;
    } 
    
    
    
    int main(int argc, char* argv[])
    {
    	WriteLog("int:", 1);
    	WriteLog("char:", '1');
    	WriteLog("float:", 1.0f);
    	return 0;
    }
    In your example condition
    Code:
    if(sizeof(&pVoidType) == sizeof(int))
    is always true, because size of pointer is always equal to size of int.

    Hob
    Last edited by Hobson; August 31st, 2005 at 09:29 AM.
    B+!
    'There is no cat' - A. Einstein

    Use &#91;code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured