473,413 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

"const <anonymous>**" and "<unknown type>" errors while compiling


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>::DerivedClass2(hsOperation<FL OAT>&) [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> >::DerivedClass1(const
<anonymous>**)'
derivedclass1.h:12: error: candidates are: DerivedClass1<double,
hsOperation<double> >::DerivedClass1(const DerivedClass1<double,
hsOperation<double> >&)
derivedclass1.h:22: error: DerivedClass1<FLOAT,
FOP>::DerivedClass1(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<d ouble>*, <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 ////////////////////////// %< %< %< %<
--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #1
3 2440
Hi,

{please try to strip the code down some more next time, that includes
combining everything into a single source file, and it's nice to somehow
mark the lines of code that correspond to the error messages.}

H. S. schrieb:

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: derivedclass2.h: In constructor `
DerivedClass2<FLOAT>::DerivedClass2(hsOperation<FL OAT>&) [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> >::DerivedClass1(const
<anonymous>**)'
derivedclass1.h:12: error: candidates are: DerivedClass1<double,
hsOperation<double> >::DerivedClass1(const DerivedClass1<double,
hsOperation<double> >&)
DerivedClass1< ... > has these ctors:
// Your user-defined one
DerivedClass1(FOP* objOPp, void(FOP::* MultOPxp)(FLOAT[], FLOAT[]));
// Compiler-generated cctor
DerivedClass1(const DerivedClass1&);

That's the candidates listed in the output above.
Now DerivedClass2's ctor looks like this:

template<class FLOAT>
inline DerivedClass2<FLOAT>::
DerivedClass2(hsOperation<FLOAT>& A){
vcVirtualFunc(&A, &hsOperation<FLOAT>::vOperationAdd); // see below
}

As it doesn't include a base initializer, the compiler has no choice but
to require a default ctor for DerivedClass1, which doesn't exist.
That's the 1st error (don't ask me where it gets the <anonymous>**
from). Basically, your ctor above is equivalent to this one:

template<class FLOAT>
inline DerivedClass2<FLOAT>::
DerivedClass2(hsOperation<FLOAT>& A) : DerivedClass1<FLOAT>(){
vcVirtualFunc(&A, &hsOperation<FLOAT>::vOperationAdd); // see below
}

Which of course can't work.
derivedclass1.h:22: error: DerivedClass1<FLOAT,
FOP>::DerivedClass1(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<d ouble>*, <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>]
When gcc mentions <unknown type>, in most cases (and yours) that's
related to "forgetting" the & with member function pointers:

// Wrong
vcVirtualFunc(&A, hsOperation<FLOAT>::vOperationAdd);
// Needs to be:
vcVirtualFunc(&A, &hsOperation<FLOAT>::vOperationAdd);

Two more things:
#ifndef _HSOPERATION_H_
#define _HSOPERATION_H_
Names beginning with an underscore followed by a capital letter and
names containing two consecutive underscores are reserved for the (C++
language) implementation. Thus, you must not use such names in your
source files.
template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(TYPE* x, TYPE* y){
X = *x;
Y = *y;
}
Why are you passing x and y as pointers? If they are always some int or
float types, passing by value comes with no penalty, otherwise a (const
as you don't modify them) reference would seem more adequate:

template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(const TYPE& x, const TYPE& y){
X = x;
Y = y;
}

Same for similar occurances, it also saves all those dereferencing (*)
operators inside the function and the addressof (&) operators in the
calling code.
template <class TYPE>
inline void hsOperation<TYPE>::GetSolution(TYPE* R)
{
*R = Result;
}


Same issue, plus why "return" the result this way, when the function
doesn't have an actual return type?

To stick with R as an output parameter, note this time it's a non-const
reference:

template <class TYPE>
inline void hsOperation<TYPE>::GetSolution(TYPE& R)
{
R = Result;
}

Or the more straightforward approach:

template <class TYPE>
inline const TYPE& hsOperation<TYPE>::GetSolution()
{
return Result;
}

Cheers,
Malte
Jul 23 '05 #2
Malte Starostik schrieb:
Why are you passing x and y as pointers? If they are always some int or
float types, passing by value comes with no penalty, otherwise a (const
as you don't modify them) reference would seem more adequate:

template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(const TYPE& x, const TYPE& y){
X = x;
Y = y;
}


For the sake of completeness, the preferred way to initialize members is
an initialization list:

template <class TYPE>
inline hsOperation<TYPE>::
hsOperation(const TYPE& x, const TYPE& y)
: X(x), Y(y)
{
}

This reduces the implicit default initialization followed by an explicit
assignment to an explicit non-default initialization.

Cheers,
Malte
Jul 23 '05 #3
Apparently, _Malte Starostik_, on 19/03/05 21:42,typed:
Hi,

{please try to strip the code down some more next time, that includes
combining everything into a single source file, and it's nice to somehow
mark the lines of code that correspond to the error messages.}
Yes, of course. Thanks for letting me know. Apologies for all the mess
in my post. I was looking for some way I could post a tgz of the source
files on the Yahoo webpage one can get on Geocities but couldn't figure
out how to upload a .tgz :(

This is one of my first posts on this newsgroup and I really appreciate
your polite note. I will surely keep this in mind.
<Some very helpful comments snipped for brevity>

Cheers,
Malte

I cannot thank you enough for your very instructive and helpful
explanations. They not only solved my problem, but they also were
helpful in providing many insights into class declarations and
inheritence. You made my day! I am actually trying to compile the
ARPACK++ library on a Linux machine using the g++ compiler I mentioned
earlier. It seems to be quite uphill task given that the code is so old.

Thanks once again for your help,
->HS

--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
2
by: Bhavin | last post by:
Hi I'm trying to set default value for input type file. <input type="File" name="tx_pdffile" accept="*.pdf" class="boxText" value="abc.pdf"> but this value (abc.pdf) doesnt appear in the text...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.