Results 1 to 4 of 4

Thread: warning C4251:

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default warning C4251:

    Hi guys,
    I'm creating a dll for my project, but having problem with
    this famous warning

    warning C4251: 'std::_Vector_val<_Ty,_Alloc>::_Alval' : class 'std::allocator<_Ty>'
    needs to have dll-interface to be used by clients of class 'std::_Vector_val<_Ty,_Alloc>'

    I had a good look at google and found some solutions which were quite satifying

    Qt Code:
    1. class COMMON_DLL_API ConnectionTable
    2. {
    3. public:
    4. struct CtRow
    5. {
    6.  
    7. };
    8.  
    9. };
    To copy to clipboard, switch view to plain text mode 
    For the above class I used the below code and it works fine
    Qt Code:
    1. template class COMMON_DLL_API std::allocator<CtRow*>;
    2. template class COMMON_DLL_API std::vector<CtRow*, std::allocator<CtRow*> >;
    3. std::vector<CtRow*> table;
    To copy to clipboard, switch view to plain text mode 
    Now my problem is with this code
    Qt Code:
    1. template<class T> class COMMON_DLL_API SynsupVector : public std::vector<T>
    2. {
    3.  
    4. };
    To copy to clipboard, switch view to plain text mode 
    For the above code I still get the same warnings. I tried using the same above
    syntaxs but get compile time errors if done so.

    Any help will be highly appreciated

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: warning C4251:

    Hi guys,
    Come on!!! provide some input please, I'm getting nightmare coz it doesnt allow me run my module.

    Help me I'm in a great problem.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: warning C4251:

    Quote Originally Posted by vermarajeev View Post
    provide some input please, I'm getting nightmare coz it doesnt allow me run my module.
    Well... it's not that easy. Templated code exists only in potentia until you instantiate the template either by using it, or like this:
    Qt Code:
    1. template class COMMON_DLL_API std::allocator<CtRow*>;
    2. template class COMMON_DLL_API std::vector<CtRow*, std::allocator<CtRow*> >;
    To copy to clipboard, switch view to plain text mode 

    That SynsupVector class is a template, so there is no physical code that you could put in a DLL and use it later. What you could try is putting all of the code in header files, but without COMMON_DLL_API. Like this:
    Qt Code:
    1. template<class T> class SynsupVector : public std::vector<T>
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    This way every application will have its own template instances and you will loose all of the benefits of shared libraries*, but at least it should work.


    * You could try to delegate a part of the implementation to a non-template class and place that class in DLL.

  4. #4
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: warning C4251:

    Quote Originally Posted by vermarajeev View Post
    Now my problem is with this code
    Qt Code:
    1. template<class T> class COMMON_DLL_API SynsupVector : public std::vector<T>
    2. {
    3.  
    4. };
    To copy to clipboard, switch view to plain text mode 
    You should take care with this also: std::vector does not have a virtual destructor, it's not really meant to be derived from; if you would delete a SynsupVector*, vector's destructor won't get called, which can turn out quite problematic..
    If you need to add functionality you're better of writing void myFunc( std::vector<T>& ) or using the vector as a member variable.
    Of course that doesn't solve the dll export problem since a template isn't compiled completely unless you use it.
    Interesting problem ;-]

Similar Threads

  1. warning
    By mickey in forum Newbie
    Replies: 5
    Last Post: 26th September 2006, 23:38
  2. Qt/Embedded Installation error during make
    By mahe2310 in forum Installation and Deployment
    Replies: 5
    Last Post: 7th September 2006, 04:05
  3. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23
  4. a Text Editor with line numbers...
    By fullmetalcoder in forum Qt Programming
    Replies: 47
    Last Post: 5th April 2006, 11:10
  5. warning message on compile not understood
    By impeteperry in forum Qt Programming
    Replies: 13
    Last Post: 23rd January 2006, 23:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.