H
H. S.
Hi,
I am trying to compile these set of C++ files and trying out class
inheritence and function pointers. Can anybody shed some light why my
compiler is not compiling them and where I am going wrong?
I am using g++ (GCC) 3.3.5 on a Debian Sarge system. The compiler complains:
//****************************
//**************************** Compiler output starts ***********
cd /home/red/tmp/testprogs/
time make
g++ -gstabs -ansi -Wall -c -I./ hstestprog.cc -o hstestprog.o
derivedclass2.h: In constructor `
DerivedClass2<FLOAT>:erivedClass2(hsOperation<FLOAT>&) [with FLOAT =
double]':
hstestprog.cc:34: instantiated from `int CallingFunc(FLOAT, FLOAT*)
[with FLOAT = double]'
hstestprog.cc:19: instantiated from here
derivedclass2.h:19: error: no matching function for call to `
DerivedClass1<double, hsOperation<double> >:erivedClass1(const
<anonymous>**)'
derivedclass1.h:12: error: candidates are: DerivedClass1<double,
hsOperation<double> >:erivedClass1(const DerivedClass1<double,
hsOperation<double> >&)
derivedclass1.h:22: error: DerivedClass1<FLOAT,
FOP>:erivedClass1(FOP*, void (FOP::*)(FLOAT*, FLOAT*)) [with FLOAT =
double, FOP = hsOperation<double>]
hstestprog.cc:34: instantiated from `int CallingFunc(FLOAT, FLOAT*)
[with FLOAT = double]'
hstestprog.cc:19: instantiated from here
derivedclass2.h:21: error: no matching function for call to `
DerivedClass2<double>::vcVirtualFunc(hsOperation<double>*, <unknown
type>)'
virtualclass.h:21: error: candidates are: void VirtualClass<FLOAT, TYPE,
FOP>::vcVirtualFunc(FOP*, void (FOP::*)(TYPE*, TYPE*)) [with FLOAT =
double,
TYPE = double, FOP = hsOperation<double>]
make: *** [hstestprog.o] Error 1
//**************************** Compiler output Ends ***********
//****************************
The source files are given below.
Thanks,
->HS
PS: Here are the source files I am trying to compile, 5 in all:
//******** hsoperation.h ***************** %< %< %< %<
#ifndef _HSOPERATION_H_
#define _HSOPERATION_H_
#include "virtualclass.h"
/*! This header file defines a template class which provides an
overloaded function that does some operation. This class mainly sets up
some data and provides the method to operate on that data. This class
can provide various methods to operate differently on the data.*/
template<class TYPE>
class hsOperation{
public:
hsOperation(TYPE* x, TYPE* y);
void vOperationAdd(TYPE* x, TYPE* y);
void GetSolution(TYPE* R);
TYPE Result;
TYPE X,Y;
};
template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(TYPE* x, TYPE* y){
X = *x;
Y = *y;
}
template <class TYPE>
inline void hsOperation<TYPE>::
vOperationAdd(TYPE* x, TYPE* y)
{
Result = (*x) + (*y);
}
template <class TYPE>
inline void hsOperation<TYPE>::GetSolution(TYPE* R)
{
*R = Result;
}
#endif //_HSOPERATION_H_
/////////// hsoperation.h ////////////// %< %< %< %<
//******** hsoperation.cc ************** %< %< %< %<
#include <cstddef>
#include <iostream>
#include "hsoperation.h"
#include "derivedclass2.h"
template <class FLOAT>
int CallingFunc(FLOAT N, FLOAT* Result);
int main()
{
//hsOperation<int> hsOP;
int i,j;
double dN, dR;
i = 2;
j = 3;
//hsOP.vOperation(&i,&j);
//std::cout << "Result: " << hsOP.Result << std::endl;
CallingFunc<double>(dN, &dR);
}
template <class FLOAT>
int CallingFunc(FLOAT N, FLOAT* pResult)
{
double di, dj;
di=3.5;
dj=10.0;
//initialize certain values here to operated upon later
hsOperation<FLOAT> matrix(&di,&dj);
//now operate on the initialized values
DerivedClass2<FLOAT> prob(matrix);
//now get the result of the operation
prob.Solution(pResult);
return 0;
} // real nonsymmetric standard problem, values and vectors, regular mode.
/////////// hsoperation.cc //////////////// %< %< %< %<
//******** derivedclass1.h *************** %< %< %< %<
#ifndef _DERIVEDCLASS1_H_
#define _DERIVEDCLASS1_H_
#include "virtualclass.h"
/*! This is the first derived class, that corresponds to ARNonSymStdEig
in arsnsym.h
*/
template<class FLOAT, class FOP>
class DerivedClass1:
public virtual VirtualClass<FLOAT, FLOAT, FOP> {
public:
DerivedClass1(FOP* objOPp, void(FOP::* MultOPxp)(FLOAT[], FLOAT[]));
};
template<class FLOAT, class FOP>
inline DerivedClass1<FLOAT, FOP>::
DerivedClass1(FOP* objOPp, void(FOP::* MultOPxp)(FLOAT[], FLOAT[])){
vcVirtualFunc(ObjOPp,MultOPxp);
}
#endif //_DERIVEDCLASS1_H_
/////////// derivedclass1.h ///////////////// %< %< %< %<
//******** derivedclass2.h ***************** %< %< %< %<
#ifndef _DERIVEDCLASS2_H_
#define _DERIVEDCLASS2_H_
#include "hsoperation.h"
#include "derivedclass1.h"
template<class FLOAT>
class DerivedClass2:
public virtual DerivedClass1<FLOAT, hsOperation<FLOAT> > {
public:
DerivedClass2(hsOperation<FLOAT>& A);
void Solution(FLOAT* pR);
};
template<class FLOAT>
inline DerivedClass2<FLOAT>::
DerivedClass2(hsOperation<FLOAT>& A){
vcVirtualFunc(&A, hsOperation<FLOAT>::vOperationAdd);
}
template<class FLOAT>
inline void DerivedClass2<FLOAT>::
Solution(FLOAT* pR){
//*pR = Result;
}
#endif //_DERIVEDCLASS2_H_
/////////// derivedclass2.h ////////////////// %< %< %< %<
//******** virtualclass.h ****************** %< %< %< %<
#ifndef _VIRTUALCLASS_H_
#define _VIRTUALCLASS_H_
/*! This is the Virtual class which will have the virtual function*/
template <class FLOAT, class TYPE, class FOP>
class VirtualClass{
public:
typedef void (FOP::* TypeOPx)(TYPE[], TYPE[]);
FOP* objOP;// Object that has MultOPx as a member function.
TypeOPx MultOPx;// Function that evaluates the product OP*x.
virtual void vcVirtualFunc(FOP*, TypeOPx);
};
template <class FLOAT, class TYPE, class FOP>
void VirtualClass<FLOAT, TYPE, FOP>::
vcVirtualFunc(FOP* objOPp, void (FOP::* MultOPxp)(TYPE[],TYPE[])){
objOP = objOPp;
MultOPx = MultOPxp;
}
#endif // _VIRTUALCLASS_H_
/////////// virtualclass.h /////////////////// %< %< %< %<
//******** Makefile ************************* %< %< %< %<
PROGRAM= hstestprog
OBJS= hstestprog.o
CXX = g++
CXX_FLAGS = -gstabs -ansi -Wall -c
CPPFLAGS= -I./
#put paths and names of libraries
LIBS=
#list other object files's pathnames here
OTHEROBS=
#lnker stuff
LD = g++
LDFLAGS = $(LIBS) -lm
####################doxygen document generation stuff####################
#config file to be used to procude the documentation
DOXFILE=
#directory created by doxygen. As specified in the dox config file.
DOXOUTDIR=
#program to produce the documentation
DOXPROG=doxygen
RM = rm -f
RMDIR= rm -rf
$(PROGRAM) : $(OBJS)
$(LD) $(LDFLAGS) $^ -o $@ $(LDFLAGS) $(OTHEROBS)
#testtnt.o:testtnt.cc
hstestprog.o: hstestprog.cc hsoperation.h virtualclass.h derivedclass1.h
derivedclass2.h
#specify the rule
%.o : %.cc
$(CXX) $(CXX_FLAGS) $(CPPFLAGS) $< -o $@
#make the documentation
####html: *.cc *.h $(DOXFILE)
#### $(RMDIR) $(DOXOUTDIR)
#### $(DOXPROG) $(DOXFILE)
#### echo "docs made"
####$(DOXFILE):
#### $(DOXPROG) -g $(DOXFILE)
cleanALL: cleanall
$(RMDIR) $(DOXOUTDIR)
#clean up operations
prune:
$(RM) *~
clean: prune
$(RM) -f $(OBJS)
cleanall: clean
$(RM) -f $(PROGRAM) *.o *~
/////////// Makefile ////////////////////////// %< %< %< %<
I am trying to compile these set of C++ files and trying out class
inheritence and function pointers. Can anybody shed some light why my
compiler is not compiling them and where I am going wrong?
I am using g++ (GCC) 3.3.5 on a Debian Sarge system. The compiler complains:
//****************************
//**************************** Compiler output starts ***********
cd /home/red/tmp/testprogs/
time make
g++ -gstabs -ansi -Wall -c -I./ hstestprog.cc -o hstestprog.o
derivedclass2.h: In constructor `
DerivedClass2<FLOAT>:erivedClass2(hsOperation<FLOAT>&) [with FLOAT =
double]':
hstestprog.cc:34: instantiated from `int CallingFunc(FLOAT, FLOAT*)
[with FLOAT = double]'
hstestprog.cc:19: instantiated from here
derivedclass2.h:19: error: no matching function for call to `
DerivedClass1<double, hsOperation<double> >:erivedClass1(const
<anonymous>**)'
derivedclass1.h:12: error: candidates are: DerivedClass1<double,
hsOperation<double> >:erivedClass1(const DerivedClass1<double,
hsOperation<double> >&)
derivedclass1.h:22: error: DerivedClass1<FLOAT,
FOP>:erivedClass1(FOP*, void (FOP::*)(FLOAT*, FLOAT*)) [with FLOAT =
double, FOP = hsOperation<double>]
hstestprog.cc:34: instantiated from `int CallingFunc(FLOAT, FLOAT*)
[with FLOAT = double]'
hstestprog.cc:19: instantiated from here
derivedclass2.h:21: error: no matching function for call to `
DerivedClass2<double>::vcVirtualFunc(hsOperation<double>*, <unknown
type>)'
virtualclass.h:21: error: candidates are: void VirtualClass<FLOAT, TYPE,
FOP>::vcVirtualFunc(FOP*, void (FOP::*)(TYPE*, TYPE*)) [with FLOAT =
double,
TYPE = double, FOP = hsOperation<double>]
make: *** [hstestprog.o] Error 1
//**************************** Compiler output Ends ***********
//****************************
The source files are given below.
Thanks,
->HS
PS: Here are the source files I am trying to compile, 5 in all:
//******** hsoperation.h ***************** %< %< %< %<
#ifndef _HSOPERATION_H_
#define _HSOPERATION_H_
#include "virtualclass.h"
/*! This header file defines a template class which provides an
overloaded function that does some operation. This class mainly sets up
some data and provides the method to operate on that data. This class
can provide various methods to operate differently on the data.*/
template<class TYPE>
class hsOperation{
public:
hsOperation(TYPE* x, TYPE* y);
void vOperationAdd(TYPE* x, TYPE* y);
void GetSolution(TYPE* R);
TYPE Result;
TYPE X,Y;
};
template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(TYPE* x, TYPE* y){
X = *x;
Y = *y;
}
template <class TYPE>
inline void hsOperation<TYPE>::
vOperationAdd(TYPE* x, TYPE* y)
{
Result = (*x) + (*y);
}
template <class TYPE>
inline void hsOperation<TYPE>::GetSolution(TYPE* R)
{
*R = Result;
}
#endif //_HSOPERATION_H_
/////////// hsoperation.h ////////////// %< %< %< %<
//******** hsoperation.cc ************** %< %< %< %<
#include <cstddef>
#include <iostream>
#include "hsoperation.h"
#include "derivedclass2.h"
template <class FLOAT>
int CallingFunc(FLOAT N, FLOAT* Result);
int main()
{
//hsOperation<int> hsOP;
int i,j;
double dN, dR;
i = 2;
j = 3;
//hsOP.vOperation(&i,&j);
//std::cout << "Result: " << hsOP.Result << std::endl;
CallingFunc<double>(dN, &dR);
}
template <class FLOAT>
int CallingFunc(FLOAT N, FLOAT* pResult)
{
double di, dj;
di=3.5;
dj=10.0;
//initialize certain values here to operated upon later
hsOperation<FLOAT> matrix(&di,&dj);
//now operate on the initialized values
DerivedClass2<FLOAT> prob(matrix);
//now get the result of the operation
prob.Solution(pResult);
return 0;
} // real nonsymmetric standard problem, values and vectors, regular mode.
/////////// hsoperation.cc //////////////// %< %< %< %<
//******** derivedclass1.h *************** %< %< %< %<
#ifndef _DERIVEDCLASS1_H_
#define _DERIVEDCLASS1_H_
#include "virtualclass.h"
/*! This is the first derived class, that corresponds to ARNonSymStdEig
in arsnsym.h
*/
template<class FLOAT, class FOP>
class DerivedClass1:
public virtual VirtualClass<FLOAT, FLOAT, FOP> {
public:
DerivedClass1(FOP* objOPp, void(FOP::* MultOPxp)(FLOAT[], FLOAT[]));
};
template<class FLOAT, class FOP>
inline DerivedClass1<FLOAT, FOP>::
DerivedClass1(FOP* objOPp, void(FOP::* MultOPxp)(FLOAT[], FLOAT[])){
vcVirtualFunc(ObjOPp,MultOPxp);
}
#endif //_DERIVEDCLASS1_H_
/////////// derivedclass1.h ///////////////// %< %< %< %<
//******** derivedclass2.h ***************** %< %< %< %<
#ifndef _DERIVEDCLASS2_H_
#define _DERIVEDCLASS2_H_
#include "hsoperation.h"
#include "derivedclass1.h"
template<class FLOAT>
class DerivedClass2:
public virtual DerivedClass1<FLOAT, hsOperation<FLOAT> > {
public:
DerivedClass2(hsOperation<FLOAT>& A);
void Solution(FLOAT* pR);
};
template<class FLOAT>
inline DerivedClass2<FLOAT>::
DerivedClass2(hsOperation<FLOAT>& A){
vcVirtualFunc(&A, hsOperation<FLOAT>::vOperationAdd);
}
template<class FLOAT>
inline void DerivedClass2<FLOAT>::
Solution(FLOAT* pR){
//*pR = Result;
}
#endif //_DERIVEDCLASS2_H_
/////////// derivedclass2.h ////////////////// %< %< %< %<
//******** virtualclass.h ****************** %< %< %< %<
#ifndef _VIRTUALCLASS_H_
#define _VIRTUALCLASS_H_
/*! This is the Virtual class which will have the virtual function*/
template <class FLOAT, class TYPE, class FOP>
class VirtualClass{
public:
typedef void (FOP::* TypeOPx)(TYPE[], TYPE[]);
FOP* objOP;// Object that has MultOPx as a member function.
TypeOPx MultOPx;// Function that evaluates the product OP*x.
virtual void vcVirtualFunc(FOP*, TypeOPx);
};
template <class FLOAT, class TYPE, class FOP>
void VirtualClass<FLOAT, TYPE, FOP>::
vcVirtualFunc(FOP* objOPp, void (FOP::* MultOPxp)(TYPE[],TYPE[])){
objOP = objOPp;
MultOPx = MultOPxp;
}
#endif // _VIRTUALCLASS_H_
/////////// virtualclass.h /////////////////// %< %< %< %<
//******** Makefile ************************* %< %< %< %<
PROGRAM= hstestprog
OBJS= hstestprog.o
CXX = g++
CXX_FLAGS = -gstabs -ansi -Wall -c
CPPFLAGS= -I./
#put paths and names of libraries
LIBS=
#list other object files's pathnames here
OTHEROBS=
#lnker stuff
LD = g++
LDFLAGS = $(LIBS) -lm
####################doxygen document generation stuff####################
#config file to be used to procude the documentation
DOXFILE=
#directory created by doxygen. As specified in the dox config file.
DOXOUTDIR=
#program to produce the documentation
DOXPROG=doxygen
RM = rm -f
RMDIR= rm -rf
$(PROGRAM) : $(OBJS)
$(LD) $(LDFLAGS) $^ -o $@ $(LDFLAGS) $(OTHEROBS)
#testtnt.o:testtnt.cc
hstestprog.o: hstestprog.cc hsoperation.h virtualclass.h derivedclass1.h
derivedclass2.h
#specify the rule
%.o : %.cc
$(CXX) $(CXX_FLAGS) $(CPPFLAGS) $< -o $@
#make the documentation
####html: *.cc *.h $(DOXFILE)
#### $(RMDIR) $(DOXOUTDIR)
#### $(DOXPROG) $(DOXFILE)
#### echo "docs made"
####$(DOXFILE):
#### $(DOXPROG) -g $(DOXFILE)
cleanALL: cleanall
$(RMDIR) $(DOXOUTDIR)
#clean up operations
prune:
$(RM) *~
clean: prune
$(RM) -f $(OBJS)
cleanall: clean
$(RM) -f $(PROGRAM) *.o *~
/////////// Makefile ////////////////////////// %< %< %< %<