Results 1 to 16 of 16

Thread: Template specification to base class

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    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.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Virtual Functions?

  7. #7

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    eh?
    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.

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    What exactly do you mean by specification? Are you saying you
    want to redefine the function in the derived class?

  9. #9

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  11. #11
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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;
    }

  12. #12

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  13. #13
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    I forgot to use my big word of the day - POLYMORPHISM.

  14. #14

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  16. #16

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yep, it didn't work
    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
  •  



Click Here to Expand Forum to Full Width