Path: utzoo!attcan!uunet!tank!ncar!unmvax!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!sorensen From: sorensen@athena.mit.edu (Alma G. Sorensen) Newsgroups: comp.lang.c++ Subject: Operator overloading with abstract classes Summary: Why can't I do this? Message-ID: <11468@bloom-beacon.MIT.EDU> Date: 16 May 89 20:53:40 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: sorensen@athena.mit.edu (Alma G. Sorensen) Distribution: comp.lang.c++ Organization: Massachusetts Institute of Technology Lines: 33 Howdy, all. Time again to approach the net with questions. I'm trying to combine virtual operators with an abstract class. Basically, I'd like to provide users of the class the ability to write functions manipulating a family of classes, without knowing which particular class they were writing operations for. An example might be N-dimensional vectors, e.g., I'd like to define a class base_vec, and then derive classes for vectors of 1, 2, 3, and 4 dimensions. Each derived class would have its own set of overloaded operators. I figured I could use pointers to the base class as the access method. This would allow the users of the class to write things like the following: void f(base_vec * a, base_vec * b) { base_vec * result; result = *a + *b; } and have '+' do the appropriate thing for whichever classes happen to be pointed to by a and b. I can't do this now because "it is not possible to define an operator function that operates exclusively on pointers." [Stroustrup, p 172.] I can't see the right way to use an abstract class without pointers, but if I use pointers, I can't do operator overloading. Help! Is there some way to get both? Thanks, Greg Sorensen sorensen@athena.mit.edu