Help in operator << >> overloading in Library
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help in operator << >> overloading in Library

  1. #1
    Join Date
    Jul 2002
    Posts
    773

    Help in operator << >> overloading in Library

    Code:
    class VAR_EXPORT VAR
    {
    public:
    
    
    
    };
    VAR_EXPORT QDataStream &operator>>(QDataStream &p_stream, QSharedPointer<Data>& p_data)
    	{
    
    	.....................
    	}
      VAR_EXPORT QDataStream & operator<<(QDataStream &p_stream, const Data & p_data)
    	{
    		..........
    	}
    	
      VAR_EXPORT QDataStream &operator<<(QDataStream &p_stream, QSharedPointer<Data> p_data)
    	{
    		return p_stream << *p_data;
    	}
    Above compile and build ok. But when i build another library that use the above, i was shown with all errors complaining operator << and >> definition of dllimport finction not allowed

    error C2491: 'operator >>' : definition of dllimport function not allowed
    error C2491: 'operator <<' : definition of dllimport function not allowed
    Last edited by mce; August 1st, 2014 at 04:41 AM.

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,359

    Re: Help in operator << >> overloading in Library

    You are supoosed to *declare* your functions with dll import/export in your .h), and the *define* them without dll import/export (in your cpp).
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center