Home  |  About  | Last |  Submit  |  Contact
AllQuests.com

Previous Question:  PHP Function stops mid loop.  Scripting Server Side (PHP, Perl, etc.)Next Question:  .  Trash Can

Question Problems with abstract class in mvs2005 ( CodeGuru Forums Visual C++ Programming )
Updated: 2008-08-12 06:10:13 (5)
Problems with abstract class in mvs2005

Hi,

I don't know if this problem has to do with Microsoft Visual Studio, I guess not... probably a mistake of mine. And I have no idea why I'm getting these errors. If someone could help me out, I'd be very thankful.

I'm trying to build my own small library with math functions and variables so my idea was to make a base class for all the variables and then derive them from this one, making complex numbers, matrixes, etc...

So I wrote a basic structure for this base abstract class and then tried compiling just to see if there were any errors, and I got the following:

Code:
1>Compiling... 1>Main.cpp 1>c:\documents and settings\crist?v?o\os meus documentos\visual studio 2005\projects\ubermath\tester\main.cpp(10) : error C2259: 'Variable' : cannot instantiate abstract class 1> due to following members: 1>c:\documents and settings\crist?v?o\os meus documentos\visual studio 2005\projects\ubermath\tester\main.cpp(11) : error C2259: 'Variable' : cannot instantiate abstract class 1> due to following members: 1>c:\documents and settings\crist?v?o\os meus documentos\visual studio 2005\projects\ubermath\tester\main.cpp(12) : error C2259: 'Variable' : cannot instantiate abstract class 1> due to following members: 1>c:\documents and settings\crist?v?o\os meus documentos\visual studio 2005\projects\ubermath\tester\main.cpp(24) : error C2259: 'Variable' : cannot instantiate abstract class 1> due to following members: 1>Build log was saved at "file://c:\Documents and Settings\Crist?v?o\Os meus documentos\Visual Studio 2005\Projects\UberMath\Tester\Debug\BuildLog.htm" 1>Tester - 4 error(s), 0 warning(s)


And this is my code:

Code:
#include<iostream> class Variable { public: virtual ~Variable(); /*Basic Algebric operators*/ virtual Variable operator+ (Variable &Other) = 0; virtual Variable operator- (Variable &Other) = 0; virtual Variable operator* (Variable &Other) = 0; virtual Variable operator/ (Variable &Other) = 0; virtual Variable& operator= (Variable &Other) = 0; /*Other Algebric operators*/ virtual Variable& operator++ () = 0; // Check to see if this is correct (prefix or postfix version), check how to do the other. virtual Variable& operator-- () = 0; virtual Variable& operator+= (Variable &Other) = 0; virtual Variable& operator-= (Variable &Other) = 0; virtual Variable& operator*= (Variable &Other) = 0; virtual Variable& operator/= (Variable &Other) = 0; /*Basic binary operators*/ virtual Variable operator^ (Variable &Other) = 0; // Check for the other ones /*Basic boolean operatos*/ virtual bool operator== (Variable &Other) = 0; virtual bool operator!= (Variable &Other) = 0; virtual bool operator< (Variable &Other) = 0; virtual bool operator<= (Variable &Other) = 0; virtual bool operator> (Variable &Other) = 0; virtual bool operator>= (Variable &Other) = 0; /*IOstream output operators*/ //look for them. private: protected: }; void main() { std:: cout << "Done!\n\n"; return; }


So thanks for reading this!

Answers: Problems with abstract class in mvs2005 ( CodeGuru Forums Visual C++ Programming )
Problems with abstract class in mvs2005

Quote:
Originally Posted by VladimirF
Hmmm... How that new derived class is going to fix errors in the BASE class???

I didn't say it would. I only explained the meaning of the error message.

edit : btw, the problem is the same as the error message. Some of his operators return a 'Variable' instead of a 'Variable &'. Abstract classes cannot be used/returned directly.



Problems with abstract class in mvs2005

Quote:
Originally Posted by Skizmo
You have functions in your class that are pure virtual. They need to be implemented, and this can only be done by creating a class that is derived of yours and that has implemented the pure virtual functions.
Hmmm... How that new derived class is going to fix errors in the BASE class???

VladimirF

Problems with abstract class in mvs2005

The error says it all.
Quote:
cannot instantiate abstract class

You have functions in your class that are pure virtual. They need to be implemented, and this can only be done by creating a class that is derived of yours and that has implemented the pure virtual functions.



Problems with abstract class in mvs2005

The following lines are your problems - they are not legal operators:

Code:
virtual Variable operator- (Variable &Other) = 0; virtual Variable operator* (Variable &Other) = 0; virtual Variable operator/ (Variable &Other) = 0; virtual Variable operator^ (Variable &Other) = 0; // Check for the other ones

You must change the return value to return a reference (Variable &).

zerver

Problems with abstract class in mvs2005

Quote:
Originally Posted by zerver
The following lines are your problems - they are not legal operators:
These errors have nothing to do with legality of the operators defined. This line generates the same error:
Code:
virtual Variable foo() = 0;
While returning an abstract class by value, you'd have to instantiate it...

VladimirF

Previous Question:  PHP Function stops mid loop.  CodeGuru Forums  Scripting Server Side (PHP, Perl, etc.)Next Question:  .  PS3Forums  Trash Can

- Source: Problems with abstract class in mvs2005 CodeGuru Forums Visual C++ Programming
- Previous Question: PHP Function stops mid loop. CodeGuru Forums Scripting Server Side (PHP, Perl, etc.)
- Next Question: . PS3Forums Trash Can





AllQuests.com


Best dedicated servers   Top dedicated servers   Cheap dedicated servers   Linux dedicated servers   Windows dedicated servers   Unmetered dedicated servers