|
-
Nov 25th, 2001, 11:39 AM
#1
Thread Starter
transcendental analytic
constant in nested class in template class
I want to put constants in a nested class of a parameterized class like this:
PHP Code:
template<class x> class borka {
public:
class borkb {
public:
static const int a;
};
static const a;
};
template<class x> const int borka<x>::a = 44;
template<class x> const int borka<x>::borkb::a = 44;
int main(){
cout << borka<int>::borkb::a << endl;
cout << borka<int>::a << endl;
return 0;
};
And I get a link error in the nested class constant:
LNK2001: unresolved external symbol "public: static int const borka<int>::borkb::a" (?a@borkb@?$borka@H@@2HB)
Help anyone?
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.
-
Nov 25th, 2001, 12:29 PM
#2
it works until you try:
Code:
cout << borka<int>::borkb::a << endl;
I dunno.
Z.
-
Nov 25th, 2001, 01:57 PM
#3
Thread Starter
transcendental analytic
Yep, the reason i have that inner constant is to show that it works within a template class but not in one nested in such, constants in nested classes in regular classes works too, this is just the special case MSVC6 doesn't like
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.
-
Nov 25th, 2001, 03:00 PM
#4
doesn't work with functions wither unless they are inline...
I'm sure it works somehow but the syntax is just too complicated.
I first thought it could be that classes nested in template classes automatically are templates too, but this doesn't work:
Code:
template<class x> const int borka<x>::borkb<x>::a = 44;
I get a lot of syntax errors. But maybe that helps you somehow. I'll continue my tries...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 03:16 PM
#5
Have you tried on other compilers?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 03:39 PM
#6
Thread Starter
transcendental analytic
Nope, and I really want it to work with MSVC6, no matter how complicated the syntax gets.
Thanks
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.
-
Nov 25th, 2001, 03:58 PM
#7
I give up ftm. I have a good book on such things which could help me, but I lent it to my cousin...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 04:04 PM
#8
Thread Starter
transcendental analytic
oh, no similar online stuff? When do you think you get your book back?
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.
-
Nov 25th, 2001, 04:19 PM
#9
2-3 days after asking.
But to be honest, he needs it more than I do. He takes a programming class and has a bad teacher. It is a very thick book describing everything from the basics of both C and C++ to the most complicated things like nested templates.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 04:22 PM
#10
Breaking news!
Using typedef you can realize it for specializations:
Code:
typedef borka<int>::borkb bbint;
const int bbint::a = 44;
int main() {
cout << borka<int>::borkb::a << endl;
return 0;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 04:24 PM
#11
doesn't work with unspecialized versions though...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 04:30 PM
#12
Thread Starter
transcendental analytic
Thank you so much! that will do unspecialized versions would be greater of course, but for the current case i'm on, I don't need it. If someone want's to extend my library then they'd had to specialize themselve 
Thanks again!
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.
-
Nov 25th, 2001, 04:34 PM
#13
You're welcome. It's always fun to try to solve those.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 05:02 PM
#14
Thread Starter
transcendental analytic
Wooohoo!
Even more breaking news!
I made a class outside templated class with all the constants, and let the nested one inherited that one and guess what It works without specialisation
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.
-
Nov 25th, 2001, 05:39 PM
#15
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|