Results 1 to 12 of 12

Thread: Template class organization

  1. #1
    Zaei
    Guest
    No, the problem comes when you actually compile the C++, instead of including it into a header. At that point, the code is already compiled into an obj, but when you try to instantiate, for instance A<int>, you get unresolved external symbols, because the actual implmentations of those functions never get compiled. I eventually changed the .cpp extensions to .inc, and included into the header, and everything works fine.

    Z.

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    This is SO FREAKY Zaei I was just going to ask that very same question!!!

    So if any one knows how to do this I would like to know too.

    All the examples I have found have all the template code in the header.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I found the answer
    Templates HAVE to be in the header, unless you have .cpp local templates

    like:
    PHP Code:
    template<class TT Test(&a&b)
    {
        
    T Temp a;
        
    b;
        
    Temp;
        return 
    Temp;
    }

    void Test2()
    {
        
    int pjz;
        
    4;
        
    7;
        
    Test<int>(p,j);
    }

    int WINAPI WinMain(HINSTANCE hInstHINSTANCE hPrevInstLPSTR lpCmdLineint nCmdShow)
    {
      
    Test2();
    .... 
    Here is where I found the answer
    http://www.codeguru.com/cgi-bin/bbs/...age=&view=&sb=
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    you are absolutely right, I never came to that situation (i generally always compile them altogether in one file)
    The compiler will find it if you specify
    PHP Code:
    A<int>::A()
    {


    but that's hardly usefull :/
    might be an ugly solution but including a macro which with you can declare which instantces you need (and it will expand to specifications with the accurate contents)
    but i'd say put them all in the same file.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well obviously the specific implementation can be in the cpp file, as long as the linker finds it.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Zaei
    Guest
    Kind of a pain, but it makes sense.

    Z.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    And one thing, it can't inline can it?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Zaei
    Guest
    I dont think templates can be inline, but Im not sure, as i dot use them very often =).

    Z.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    LOL, I would never even use templates if they wouldn't inline well, maybe, but that would suck insaneously!
    templates advocates inlining!
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Zaei
    Guest
    Mah bad =). Like i said, I dont use them very much.

    Z.

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    you should! you'll learn that most of the things you do, you only need to do once
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by kedaman
    you should! you'll learn that most of the things you do, you only need to do once
    Such as talking to Kedaman...you only need to say one thing and he'll provide you with endless bits of information
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

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



Click Here to Expand Forum to Full Width