|
-
Feb 14th, 2002, 04:14 PM
#1
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.
-
Feb 14th, 2002, 05:09 PM
#2
Frenzied Member
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

-
Feb 14th, 2002, 05:37 PM
#3
Frenzied Member
I found the answer
Templates HAVE to be in the header, unless you have .cpp local templates
like:
PHP Code:
template<class T> T Test(T &a, T &b)
{
T Temp = a;
a = b;
b = Temp;
return Temp;
}
void Test2()
{
int p, j, z;
p = 4;
j = 7;
z = Test<int>(p,j);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int 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

-
Feb 14th, 2002, 05:43 PM
#4
transcendental analytic
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.
-
Feb 14th, 2002, 05:46 PM
#5
transcendental analytic
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.
-
Feb 14th, 2002, 07:45 PM
#6
Kind of a pain, but it makes sense.
Z.
-
Feb 14th, 2002, 10:46 PM
#7
transcendental analytic
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.
-
Feb 14th, 2002, 11:14 PM
#8
I dont think templates can be inline, but Im not sure, as i dot use them very often =).
Z.
-
Feb 14th, 2002, 11:24 PM
#9
transcendental analytic
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.
-
Feb 15th, 2002, 09:34 AM
#10
Mah bad =). Like i said, I dont use them very much.
Z.
-
Feb 15th, 2002, 06:01 PM
#11
transcendental analytic
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.
-
Feb 16th, 2002, 02:58 PM
#12
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|