Results 1 to 3 of 3

Thread: Template of ingredient class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    29
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Template of ingredient class

    I want create class with pattern of function. When I add definition of function to *.cpp file and call it in mainwindow.cpp, I have bugs:
    Qt Code:
    1. mainwindow.o:-1: error: In function `ZN10MainWindowC2EP7QWidget':
    2. mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
    3. mainwindow.o:-1: error: In function `ZN10MainWindowC1EP7QWidget':
    4. mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
    5. mainwindow.o:-1: error: In function `ZN10MainWindow11startSearchEv':
    6. mainwindow.cpp:46: undefined reference to `void readmemory::test<int>(int)'
    7. :-1: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    It's my exemplary code:
    class.h
    Qt Code:
    1. class Pattern{
    2. template<typename T> void function(T);
    3. };
    To copy to clipboard, switch view to plain text mode 

    class.cpp
    Qt Code:
    1. template<typename T>
    2. void Pattern::function(T a)
    3. {
    4. //code
    5. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. Pattern patternClass;
    2. int a;
    3. patternClass.function(a);
    To copy to clipboard, switch view to plain text mode 
    I tried use "export" like in Visual Studio and include class.cpp to class.h, but it doesn't work. Is it possible to use template like in my test code?
    Last edited by Trok; 21st August 2009 at 11:05.

Similar Threads

  1. Extending two class "the same way"
    By caduel in forum General Programming
    Replies: 3
    Last Post: 22nd July 2009, 22:55
  2. class in the class
    By baray98 in forum General Programming
    Replies: 2
    Last Post: 23rd July 2008, 07:01
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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.