Results 1 to 2 of 2

Thread: Template class problem

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Template class problem

    Hi,

    I have 3 DLLs that use the same static variable from a template class instance, such as:

    1st DLL:
    Qt Code:
    1. template <typename T>
    2. class Foo {
    3.  
    4. public:
    5.  
    6. static Foo<T>& instance() {
    7. static Foo<T> obj;
    8. return obj;
    9. }
    10.  
    11. void add( ... ) {
    12. ...
    13. }
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 

    In 2nd dll, I call

    Qt Code:
    1. Foo<myClass>::instance().add( ... );
    To copy to clipboard, switch view to plain text mode 


    In 3nd dll, I also call

    Qt Code:
    1. Foo<myClass>::instance().add( ... );
    To copy to clipboard, switch view to plain text mode 


    In linux things work fine. The Foo<myClass>::instance() contains the 2 items I "add"

    However, in Windows, they don't know each other. It appears each has their own "instance". How can I export the instance so all DLLs share it?

    Thanks!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Template class problem

    Last edited by amleto; 12th June 2012 at 18:33.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 4
    Last Post: 25th June 2010, 09:21
  2. QModelIndex Mapping in Template QWidget Class
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2010, 07:19
  3. Template of ingredient class
    By Trok in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 12:27
  4. Replies: 1
    Last Post: 15th April 2008, 23:15
  5. Template class
    By steg90 in forum General Programming
    Replies: 15
    Last Post: 12th June 2007, 20:49

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.