[an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive] (none)
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive] (none)
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
Compiler Fejl ved abstrakte klasser
To : sslug@sslug
Subject : Compiler Fejl ved abstrakte klasser
From : Allan Nielsen <sslug@sslug>
Date : Mon, 26 Apr 2004 22:42:20 +0200
References : <c5tdeb$iqe$1@www.sslug.dk >
User-agent : Mozilla Thunderbird 0.5 (X11/20040306)
Hej
Jeg er gået i gang med at programmer et program som i første omgang skal
kunne tolke en string bestående af et matematisk udtryk, og retuner det
beregnet tal, f.eks 2*3+4 = 10.
Til at gøre dette har jeg lavet følgende klasser heraki:
Operator som er den øverste klasse, og som er erklaret abstrakt,
Operator1, Operator2, Operator3, Operator4 ... som arver fra Operater
klassen, disse er også abstrakte klasser.
Tilsidst er der de matematiske operator, plus, minus, gange, osv, som
arver fra Operator2 pågrund af at de tager 2 arkumenter.
sin(), ln(), sqrt() , osv. arver fra Operator1 da de kun tager 1 argument.
Operator0, er normale tal.
compiler siger følgende:
f1(Operator*, Operator*)':
*/home/allan/Projects/cpp/stringmath2/src/stringmath2.cpp:19: error:
`Operator' is an inaccessible base of `Oplus'
*/home/allan/Projects/cpp/stringmath2/src/stringmath2.cpp: I function
'Operator*
*f2(Operator*, Operator*)':
*/home/allan/Projects/cpp/stringmath2/src/stringmath2.cpp:24: error:
`Operator' is an inaccessible base of `Ominus'
*/home/allan/Projects/cpp/stringmath2/src/stringmath2.cpp: I function 'int
*main(int, char**)':
*/home/allan/Projects/cpp/stringmath2/src/stringmath2.cpp:40: error:
`Operator' is an inaccessible base of `Operator0'
*make[2]: *** [stringmath2.o] Fejl 1
den tilførende kode ser således ud (dette er main metoden, og jeg ved
godt at det jeg laver ikke er optimal, men det giver menig når det
bliver færdig!)
(dette er bare den udsnit som jeg mener fejlen ligger i, hele koden er
ved hæftte)
18 Operator* f1(Operator* s1,Operator* s2){
19 Operator* o = new Oplus(s1, s2, '\0');
20 return o;
21 }
22
23 Operator* f2(Operator* s1,Operator* s2){
24 Operator* o = new Ominus(s1, s2,'\0');
25 return o;
26 }
.....
32 int returVeardi = 0;
33 Operator0* s1 = new Operator0(2, 0);
34 Operator0* s2 = new Operator0(5, 0);
35
36 Operator * ( * fun_array[2])(Operator* , Operator*) = {f1, f2};
37
38 fun_array[returVeardi](s1, s2);
MVH
Allan Nielsen
PS
Jeg er stadig ny begybder til cpp, så i må bære over med mig hvis jeg
stiller dumme spørgsmål
bin_PROGRAMS = stringmath2
stringmath2_SOURCES = stringmath2.cpp operator.cpp operator2.cpp oplus.cpp ominus.cpp operator0.cpp
# set the include path found by configure
INCLUDES= $(all_includes)
# the library search path.
stringmath2_LDFLAGS = $(all_libraries)
noinst_HEADERS = operator.h operator2.h oplus.h ominus.h operator0.h
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
AR = @AR@
AS = @AS@
CC = @CC@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
GCJ = @GCJ@
GCJFLAGS = @GCJFLAGS@
HAVE_LIB = @HAVE_LIB@
LIB = @LIB@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIB = @LTLIB@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
RC = @RC@
STRIP = @STRIP@
VERSION = @VERSION@
bin_PROGRAMS = stringmath2
stringmath2_SOURCES = stringmath2.cpp operator.cpp operator2.cpp oplus.cpp ominus.cpp operator0.cpp
# set the include path found by configure
INCLUDES = $(all_includes)
# the library search path.
stringmath2_LDFLAGS = $(all_libraries)
noinst_HEADERS = operator.h operator2.h oplus.h ominus.h operator0.h
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
bin_PROGRAMS = stringmath2$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
stringmath2_OBJECTS = stringmath2.$(OBJEXT) operator.$(OBJEXT) \
operator2.$(OBJEXT) oplus.$(OBJEXT) ominus.$(OBJEXT) \
operator0.$(OBJEXT)
stringmath2_LDADD = $(LDADD)
stringmath2_DEPENDENCIES =
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
HEADERS = $(noinst_HEADERS)
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
DEP_FILES = .deps/ominus.P .deps/operator.P .deps/operator0.P \
.deps/operator2.P .deps/oplus.P .deps/stringmath2.P
SOURCES = $(stringmath2_SOURCES)
OBJECTS = $(stringmath2_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cpp .lo .o .obj .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-binPROGRAMS:
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
distclean-binPROGRAMS:
maintainer-clean-binPROGRAMS:
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(bindir)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
if test -f $$p; then \
echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
list='$(bin_PROGRAMS)'; for p in $$list; do \
rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
done
# FIXME: We should only use cygpath when building on Windows,
# and only if it is available.
.c.obj:
$(COMPILE) -c `cygpath -w $<`
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
-rm -f *.$(OBJEXT)
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
.s.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.S.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
maintainer-clean-libtool:
stringmath2$(EXEEXT): $(stringmath2_OBJECTS) $(stringmath2_DEPENDENCIES)
@rm -f stringmath2$(EXEEXT)
$(CXXLINK) $(stringmath2_LDFLAGS) $(stringmath2_OBJECTS) $(stringmath2_LDADD) $(LIBS)
.cpp.o:
$(CXXCOMPILE) -c $<
.cpp.obj:
$(CXXCOMPILE) -c `cygpath -w $<`
.cpp.lo:
$(LTCXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags $$unique $(LISP))
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = src
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.cpp
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.cpp
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am: install-binPROGRAMS
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-binPROGRAMS
uninstall: uninstall-am
all-am: Makefile $(PROGRAMS) $(HEADERS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(bindir)
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-binPROGRAMS mostlyclean-compile \
mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-binPROGRAMS clean-compile clean-libtool clean-tags \
clean-depend clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-binPROGRAMS distclean-compile distclean-libtool \
distclean-tags distclean-depend distclean-generic \
clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-binPROGRAMS \
maintainer-clean-compile maintainer-clean-libtool \
maintainer-clean-tags maintainer-clean-depend \
maintainer-clean-generic distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir \
mostlyclean-depend distclean-depend clean-depend \
maintainer-clean-depend info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
#include "ominus.h"
Ominus::Ominus(Operator* child1, Operator* child2, Operator* parent) : Operator2(child1, child2, parent, "+")
{
}
double Ominus::getDouble()
{
return child1->getDouble() + child1->getDouble();
}
std::string Ominus::getSymbol(){
return symbol;
}
Ominus::~Ominus()
{
}
#ifndef OMINUS_H
#define OMINUS_H
#include <string>
#include "operator.h"
#include "operator2.h"
/**
@author Allan W. Nielsen
*/
class Ominus : Operator2{
public:
Ominus(Operator* child1, Operator* child2, Operator* parent);
double getDouble();
std::string getSymbol();
~Ominus();
};
#endif
#include "operator.h"
Operator::Operator(Operator* parent, int iNumberOfArg)
{
this->iNumberOfArg = iNumberOfArg;
}
Operator::~Operator()
{
}
#ifndef OPERATOR_H
#define OPERATOR_H
/**
@author Allan W. Nielsen
*/
class Operator{
public:
Operator* parent;
int iNumberOfArg;
Operator(Operator* parent, int iNumberOfArg);
virtual double getDouble() = 0;
~Operator();
};
#endif
#include "operator0.h"
Operator0::Operator0(int i, Operator* parent) : Operator(parent, 0)
{
this->i = i;
}
double Operator0::getDouble(){
return (double) i;
}
Operator0::~Operator0()
{
}
#ifndef OPERATOR0_H
#define OPERATOR0_H
#include "operator.h"
/**
@author Allan W. Nielsen
*/
class Operator0 : Operator{
public:
int i;
Operator0(int i, Operator * parent);
double getDouble();
~Operator0();
};
#endif
#include "operator2.h"
Operator2::Operator2(Operator* child1, Operator* child2, Operator* parent, std::string symbol) : Operator(parent, 2)
{
this->child1 = child1;
this->child2 = child2;
this->symbol = symbol;
}
Operator2::~Operator2()
{
}
#ifndef OPERATOR2_H
#define OPERATOR2_H
#include <string>
#include "operator.h"
/**
@author Allan W. Nielsen
*/
class Operator2 : public Operator {
public:
Operator* child1;
Operator* child2;
std::string symbol;
Operator2(Operator* child1, Operator* child2, Operator* parent, std::string symbol);
virtual std::string getSymbol() = 0;
~Operator2();
};
#endif
#include "oplus.h"
Oplus::Oplus(Operator* child1, Operator* child2, Operator* parent) : Operator2(child1, child2, parent, "+")
{
}
double Oplus::getDouble()
{
return child1->getDouble() + child1->getDouble();
}
std::string Oplus::getSymbol(){
return symbol;
}
Oplus::~Oplus()
{
}
#ifndef OPLUS_H
#define OPLUS_H
#include <string>
#include "operator.h"
#include "operator2.h"
/**
@author Allan W. Nielsen
*/
class Oplus : Operator2{
public:
Oplus(Operator* child1, Operator* child2, Operator* parent);
double getDouble();
std::string getSymbol();
~Oplus();
};
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include "oplus.h"
#include "operator0.h"
#include "operator.h"
#include "ominus.h"
//sslug@sslug
using namespace std;
Operator* f1(Operator* s1,Operator* s2){
Operator* o = new Oplus(s1, s2, '\0');
return o;
}
Operator* f2(Operator* s1,Operator* s2){
Operator* o = new Ominus(s1, s2,'\0');
return o;
}
int main(int argc, char *argv[])
{
cout << "Hello, world!" << endl;
int returVeardi = 0;
Operator0* s1 = new Operator0(2, 0);
Operator0* s2 = new Operator0(5, 0);
Operator * ( * fun_array[2])(Operator* , Operator*) = {f1, f2};
fun_array[returVeardi](s1, s2);
return 0;
}
Questions about the web-pages to <www_admin >.
Last modified
2005-08-10, 22:43 CEST
[an error occurred while processing this directive] This page is maintained by
[an error occurred while processing this directive]MHonArc
[an error occurred while processing this directive] #
[an error occurred while processing this directive] *