About Store Forum Documentation Contact



Post Reply 
Advanced programming question (C++)
Author Message
BlackHornet Offline
Member

Post: #1
Advanced programming question (C++)
As I don't really know where to put, its not really EE related, but is based on something I wondered when browsing the EE headers:

I always wonder how Grzegorz managed to split up header and source of the template classes.

I searched the web and found nothing that answers the question (or at least I'm searching for the wrong thing). I always thought definition and implementation needs to be within one class, but it looks like he managed to split into header and sources. While the header are published for us to be used.

Whenever I try to create a template class with just a constuctor, I'll get a LNK2019 when moving the constructors source from header to source file.

Template-Header:
Code:
template<typename TYPE>
class TClass
{
    TClass();
}

Template-Source:
Code:
template<typename TYPE>
TClass<TYPE>::TClass()
{
}
Note:
The class is part of a static library being linked by another project.

And in that another project I'll get a LNK2019 whenever I want to use that class within my code:
TClass<int> _intInstance;

Maybe anybody can give me a hint how to solve this problem, like he did with Esenthel...still wondering how smile

If you ask where this occured: "Mem Continiuous.h" for example, in fact all memory containers are build like that in EE.
(This post was last modified: 04-21-2013 10:31 AM by BlackHornet.)
04-21-2013 10:31 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Sherincall Offline
Member

Post: #2
RE: Advanced programming question (C++)
Not sure how EE does it (and I can't look at it right now), but one way to do it would be to have a precompiled version of said header with the implementation, and a second one for our viewing.

So when he includes the file, the preprocessor will actually get the precomp, but if you search for the filename, you'll get the reduced version.

Another thing would be to have the declaration and definition in different header files (whatever the extension), and then take care to include them both somehow in correct order. The second could be hidden in some ways, or precompiled (if the compiler supports more than one precomp / precomps after regular headers - which VS doesn't).

Or, if it is just an Esenthel Script thing, he could have just removed the limitation.

Other than that.. I've no idea.
04-21-2013 11:23 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #3
RE: Advanced programming question (C++)
04-22-2013 12:59 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Advanced programming question (C++)
Function body for templates must be included in the headers as well.
Many EE template func bodies are just separated and stored in another header file Misc/Templates.h
04-22-2013 10:09 AM
Find all posts by this user Quote this message in a reply
BlackHornet Offline
Member

Post: #5
RE: Advanced programming question (C++)
Edit: OH, never have seen that file before, thank you very much! ^^



Thanks Zervox, that are some really nice approaches, but id doesn't make it clear for 100% in case of EE:

- Method 1: Esenthel don't know about custom structs defined by the client and used by a mem container
- Method 2: I don't see any implementation include in any of the Memory Container examples
- Method 3: There is no implementation include in the "Installation"-Headers files

Is there anything else possible, as I don't really see it right now :/
(This post was last modified: 04-22-2013 10:31 AM by BlackHornet.)
04-22-2013 10:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Advanced programming question (C++)
In Code Editor you can just middle mouse click a function and it will jump between func definition/declaration.
04-22-2013 10:59 AM
Find all posts by this user Quote this message in a reply
Post Reply