Problem z metodą czysto wirtualną
Ostatnio zmodyfikowano 2013-01-06 23:11
grizzPL Temat założony przez niniejszego użytkownika |
Problem z metodą czysto wirtualną » 2013-01-06 22:47:07 Visual C++ 2008. Muszę napisać prosty program obiektowo na zaliczenie. Wiem, że jest brzydko napisany, ale zadanie jest takie, że nie chciało mi się tego ładnie pisać ;) Wyskakuje mi kilka błędów i nie jestem pewny, dlaczego: Gra.h #pragma once using namespace System;
ref class Gra { public: Gra( void ); String ^ getNazwa(); String ^ getWydawca(); String ^ getRodzaj(); int getRokWydania(); String ^ getAutor(); char getOcena(); virtual double getCena() = 0; void setNazwa( String ^ _nazwa ); void setWydawca( String ^ _wydawca ); void setRodzaj( String ^ _rodzaj ); void setRokWydania( int _rok ); void setAutor( String ^ _autor ); void setOcena( char _ocena ); void setCenaPodstawowa( double _cena ); protected: String ^ nazwa; String ^ wydawca; String ^ rodzaj; int rokWydania; String ^ autor; char ocena; double cenaPodstawowa; bool sprawdzRokWydania( int rok ); double cena; };
GraKonsolowa.h #pragma once #include "gra.h"
using namespace System;
ref class GraKonsolowa : public Gra { public: GraKonsolowa( void ); GraKonsolowa( String ^ _nazwa, String ^ _wydawca ); double getCena(); void setNazwaKonsoli( String ^ _nazwaKonsoli ); String ^ getNazwaKonsoli(); private: double kosztLicencji; String ^ nazwaKonsoli; };
GraPC.h #pragma once #include "gra.h" using namespace System;
ref class GraPC : public Gra { public: GraPC( void ); GraPC( String ^ nazwa, String ^ wydawca ); double getCena(); String ^ getProcesor(); void setProcesor( String ^ _procesor ); private: String ^ procesor; };
Błędy: 1>------ Build started: Project: Programowanie, Configuration: Debug Win32 ------ 1>Compiling... 1>Programowanie.cpp 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(5) : warning C4570: 'Gra' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraKonsolowa.h(12) : error C4484: 'GraKonsolowa::getCena' : matches base ref class method 'Gra::getCena', but is not marked 'virtual', 'new' or 'override'; 'new' (and not 'virtual') is assumed 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1> Specify 'virtual' and 'override' to override the ref class virtual method 1> Specify 'virtual' and 'new' to hide the ref class virtual method with a new virtual method 1> Specify 'new' (and not 'virtual') to hide the ref class virtual method with a non-virtual method 1> Position for 'new' and 'override' keywords is after method parameter list 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraKonsolowa.h(6) : warning C4570: 'GraKonsolowa' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraPC.h(11) : error C4484: 'GraPC::getCena' : matches base ref class method 'Gra::getCena', but is not marked 'virtual', 'new' or 'override'; 'new' (and not 'virtual') is assumed 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1> Specify 'virtual' and 'override' to override the ref class virtual method 1> Specify 'virtual' and 'new' to hide the ref class virtual method with a new virtual method 1> Specify 'new' (and not 'virtual') to hide the ref class virtual method with a non-virtual method 1> Position for 'new' and 'override' keywords is after method parameter list 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraPC.h(5) : warning C4570: 'GraPC' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Form1.h(385) : error C2259: 'GraKonsolowa' : cannot instantiate abstract class 1> due to following members: 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1>GraPC.cpp 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(5) : warning C4570: 'Gra' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraPC.h(11) : error C4484: 'GraPC::getCena' : matches base ref class method 'Gra::getCena', but is not marked 'virtual', 'new' or 'override'; 'new' (and not 'virtual') is assumed 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1> Specify 'virtual' and 'override' to override the ref class virtual method 1> Specify 'virtual' and 'new' to hide the ref class virtual method with a new virtual method 1> Specify 'new' (and not 'virtual') to hide the ref class virtual method with a non-virtual method 1> Position for 'new' and 'override' keywords is after method parameter list 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraPC.h(5) : warning C4570: 'GraPC' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1>.\GraPC.cpp(18) : error C2065: 'cenaPodstawowa' : undeclared identifier 1>GraKonsolowa.cpp 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(5) : warning C4570: 'Gra' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraKonsolowa.h(12) : error C4484: 'GraKonsolowa::getCena' : matches base ref class method 'Gra::getCena', but is not marked 'virtual', 'new' or 'override'; 'new' (and not 'virtual') is assumed 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1> Specify 'virtual' and 'override' to override the ref class virtual method 1> Specify 'virtual' and 'new' to hide the ref class virtual method with a new virtual method 1> Specify 'new' (and not 'virtual') to hide the ref class virtual method with a non-virtual method 1> Position for 'new' and 'override' keywords is after method parameter list 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\GraKonsolowa.h(6) : warning C4570: 'GraKonsolowa' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\gra.h(15) : see declaration of 'Gra::getCena' 1>Gra.cpp 1>c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(5) : warning C4570: 'Gra' : is not explicitly declared as abstract but has abstract functions 1> 'double Gra::getCena(void)' : is abstract 1> c:\users\grizz_000\documents\visual studio 2008\projects\programowanie\programowanie\Gra.h(15) : see declaration of 'Gra::getCena' 1>.\Gra.cpp(45) : error C2065: '_rodzaj' : undeclared identifier 1>Generating Code... 1>Build log was saved at "file://c:\Users\grizz_000\Documents\Visual Studio 2008\Projects\Programowanie\Programowanie\Debug\BuildLog.htm" 1>Programowanie - 7 error(s), 8 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
DejaVu |
» 2013-01-06 22:57:59 |
|
grizzPL Temat założony przez niniejszego użytkownika |
» 2013-01-06 23:11:14 Ale skoro klasa staje się abstrakcyjna kiedy ma metodę czysto wirtualną (a Gra ma), to czemu kompilator stwierdza, że nie jest poprawnie oznaczona? I czemu GraKonsolowa ma niby metody wirtualne, skoro nie ma - przesłania tą z klasy bazowej? Kod pisałem ja :) Nie pamiętam, czemu w C++/CLI, pisałem to kilka tygodni temu, a teraz pomyślałem, że wreszcie poprawię :/
--- UPDATE: Chyba rozwiązałem problem ;) dzięki za linka. |
|
« 1 » |