templates and MFC

This is a discussion on templates and MFC within the Windows Programming forums, part of the Platform Specific Boards category; I am having a problem getting a template class to work in an MFC App. The general idea is that ...

  1. #1
    Unregistered
    Guest

    templates and MFC

    I am having a problem getting a template class to work in an MFC App. The general idea is that I have this templatized Clipboard class, which will register itself and call GlobalAlloc() for the type, and then the user calls a Get() function to get a pointer to the type.

    Anyway, I've written templates before, and it was never really a problem. Now it's really turning into a pain though. The class compiles fine, but every single constructor/destructor/member function turns up as an unresolved external for the instantiated type.

    The .cpp file is a part of the project, and is being compiled in.

    The only thing I can think of is that I need some sort of compiler switch turned on for templates, which is turned off in an MFC app by default. Does anyone know if this may be the case?

    Or if not, any ideas on what the hell is going on? I'm going crazy..there really isn't anything else I can think to do to get this code to work.

    Thanks in advance for any info.

  2. #2
    Unregistered
    Guest
    I figured out the problem, but I still dont understand. I found a bug that was present in VC4 or something, and it said that if you have nested template classes, they would come up as unresolved externals for the member functions, so the work around was to declare all functions inline and put the code directly into the header file. Well, I wasnt using nested classes, and I was using VC6, but whatever, I decided to give it a go. And inlining the code works.

    Is this a bug? Can someone else confirm this? I know in a data structures class I used templates to make a queue, tree, stack, etc, and that code worked fine under VC6, so I dont know why now all of the sudden it doesnt work.

    What a pain....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Automation (or similar) without MFC
    By Robert602 in forum Windows Programming
    Replies: 0
    Last Post: 11-14-2002, 09:29 AM
  2. Is this book any good to me?
    By The Gweech in forum Windows Programming
    Replies: 10
    Last Post: 07-20-2002, 05:50 PM
  3. Tab controls - MFC (revived)
    By Robert602 in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21