|
-
Dec 9th, 2001, 04:31 PM
#1
Thread Starter
transcendental analytic
Template specification to base class
I want to know if it's somehow possible to in a sub class do a specification of a template function within it's baseclass, or somehow cheat it so that i can have specifications in both.
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.
-
Dec 10th, 2001, 10:41 AM
#2
Did I get this right?
You have a template base class and you derived another class from it. You now want to make a specification of a member function of the base class in the derived class. Is this it?
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.
-
Dec 10th, 2001, 07:02 PM
#3
Thread Starter
transcendental analytic
Nope I have a template function within a base class, and I want to do a specification of it in the derived class. (I wonder how you specificate a non template function )
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.
-
Dec 11th, 2001, 07:43 AM
#4
I think we mean the same...
What have you tried? My compiler isn't working at the mo, but I'll try to come up with ideas you can try. Just show me the code.
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.
-
Dec 12th, 2001, 02:27 AM
#5
Thread Starter
transcendental analytic
Hmm, i'll think i'll leave it for now, MSVC6 compiler is such an ******* anyway, i get internal compiler errors regularily now :/
If i ever get it work again i'll post the code.
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.
-
Dec 12th, 2001, 02:33 AM
#6
Frenzied Member
-
Dec 12th, 2001, 02:54 AM
#7
Thread Starter
transcendental analytic
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.
-
Dec 12th, 2001, 03:24 AM
#8
Frenzied Member
What exactly do you mean by specification? Are you saying you
want to redefine the function in the derived class?
-
Dec 12th, 2001, 03:28 AM
#9
Thread Starter
transcendental analytic
um not really, a template function will instantiate for the derived class in the base but is to be specified in the base class, something like:
class a{
template <class A>func(A pa){};
};
class b: public a{
template <>func<int>(int pa){};
};
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.
-
Dec 12th, 2001, 03:35 AM
#10
Thread Starter
transcendental analytic
A solution would be to put this into the derived,
template <class A>func(A pa){a::func(pa);};
but thats not the point, I have loads of them inside inside a range of classes and i want to have a common base class to derive them from but still be able to do specifications in the derived classes.
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.
-
Dec 12th, 2001, 03:36 AM
#11
Frenzied Member
I think you need to make the function virtual in you base class.
Virtual functions allow the derived class to provide an alternative
implementation of a base class function.
Ex:
Code:
#include <iostream>
#include <string>
using namespace std;
class Shape{
protected:
string Name;
public:
Shape(){ }
virtual int Perimeter(void)
{
return 0;
}
};
class Rectangle : public Shape {
protected:
int width, height;
public:
Rectangle() : width(0), height(0) { }
Rectangle(int a, int b) : width(a), height(b) { }
int Perimeter(void)
{
return 2*width + 2*height;
}
};
class Square : public Shape {
protected:
int side;
public:
Square() : side(0) { }
Square(int a) : side(a) { }
int Perimeter(void)
{
return 4*side;
}
};
void main(void) {
Shape *ptr;
ptr = new Rectangle(2,4);
cout << ptr->Perimeter() << endl;
ptr = new Square(5);
cout << ptr->Perimeter() << endl;
delete ptr;
}
-
Dec 12th, 2001, 03:40 AM
#12
Thread Starter
transcendental analytic
No, I want to avoid virtual functions at all costs, because they imply overheads and breaks my inlining policy. Besides I won't have any base pointers around, the inheritance i want to do is only for readability purposes
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.
-
Dec 12th, 2001, 03:54 AM
#13
Frenzied Member
I forgot to use my big word of the day - POLYMORPHISM.
-
Dec 12th, 2001, 04:12 AM
#14
Thread Starter
transcendental analytic
hehe, POLYMORPHEUS just another dream that i wanted to change
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.
-
Dec 12th, 2001, 11:19 AM
#15
have you tried
Code:
class a{
template <class A>func(A pa){};
};
class b: public a{
template <>a::func<int>(int pa){};
};
?
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.
-
Dec 12th, 2001, 11:22 AM
#16
Thread Starter
transcendental analytic
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.
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
|