Results 1 to 11 of 11

Thread: Strategy to pass custom structures to a function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Strategy to pass custom structures to a function

    If I'd want to use a function with a lot of custom structures, which is the correct way ?
    - Have I dot write a file with all my structures and include it the classes that are going to use it ?
    - A template only works with basic types ? If i want to use with custom structures I have to include it , isn`t?
    - By last, is it preferable to use templates agaist define a lot of overloaded functions ?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strategy to pass custom structures to a function

    It all depends on the function and the structures.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strategy to pass custom structures to a function

    My functions are going to be used both to save data into buffer and/or to save data to binary files.
    Thanks WY.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Strategy to pass custom structures to a function

    Have I dot write a file with all my structures and include it the classes that are going to use it ?
    Every class or fucntion that needs to use a members of your custom structures, needs to have access to structure definition, so basically a file with structure definition needs to be included. You may want to search for info on "forward declarations" too.
    A template only works with basic types ? If i want to use with custom structures I have to include it , isn`t?
    Templates works perfectly fine with compex types. lIf you want to use a given type in template, compiler needs to know the type definition when instantiating a template class.
    You may want to read this : Thinking in C++ - chapter 16 "Introduction to Templates"

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strategy to pass custom structures to a function

    Thanks stampede
    Another question ... I dont know what is the reason because I cant use I struct (stored at a #include file) in my main header file ? (I only can use it at the implementation code)????
    Thanks

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Strategy to pass custom structures to a function

    I don't understand, can you provide a short code example ?

  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strategy to pass custom structures to a function

    mmm. still I dont know whats the problem (I cant send you the code because it is a big project with multiple files..)
    I hope to fix it myself (and give here an explanation...)
    Thanks

    solved:
    I have a #include fileA.h at my .h file and into my cpp file .
    By any reason the compiler was making something strange.
    Last edited by tonnot; 22nd June 2011 at 15:52.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strategy to pass custom structures to a function

    Compilers don't do strange things, programmers do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strategy to pass custom structures to a function

    But is there any explanation ?
    Why a duplicate #include was generating that kind of error ?
    Thanks

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strategy to pass custom structures to a function

    The explanation is you messed something in your code. What it is, I don't know, I haven't seen it. If I were to guess, I'd say your header file is missing a guard protecting it from being included multiple times during the same compilation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strategy to pass custom structures to a function

    ok, thanks

Similar Threads

  1. Pass data from QT to javascript function
    By thanhluanbk88 in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2011, 10:40
  2. Replies: 3
    Last Post: 9th February 2011, 07:28
  3. Replies: 13
    Last Post: 30th November 2010, 12:47
  4. Replies: 14
    Last Post: 1st December 2009, 20:45
  5. How to pass a QComboBox to a function?
    By Ricardo_arg in forum General Programming
    Replies: 4
    Last Post: 9th March 2008, 22:16

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
  •  
Qt is a trademark of The Qt Company.