This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Multiple entries in impl. of pure virtual function.


Hi all.  I'm a bit confused about something and wondering if someone could 
clear it up.  

Suppose that I have some class which implements an interface:
e.g.
//************************
// Impl.cc
class SystemHess{
	vritual void projectOnHessian(const std::valarray<double>& in,
			         	       std::valarray<double>& out)=0;
};

class SystemPatchHess : public SomeOtherClass, public Interface{
	void projectOnHessian(const std::valarray<double>& in,
			         std::valarray<double>& out);
};

void Impl::projectOnHessian(const std::valarray<double>& in,
			    std::valarray<double>& out){
	//do some stuff
}

//********************************

If I do a "g++ -c Impl.cc" I get an object file with the following in the sym 
table (after | c++filt):
------------------------------------------------------------------
119: 00000518    26 FUNC    LOCAL  DEFAULT 1 
_GLOBAL__I__ZN15SystemHessPatch16projectOnHessianERKSt8valarrayIdERS1_

125: 00000000  1216 FUNC    GLOBAL DEFAULT    1 
SystemHessPatch::projectOnHessian(std::valarray<double> const&, 
std::valarray<double>&)

206: 00000000   112 OBJECT  WEAK   DEFAULT  127 vtable for SystemHessPatch
------------------------------------------------------------------

If I try to duplicate the results with a simpler class following this same 
scenario, I get only the latter of these two entries.

If I try to link against the .o file, I get the following:
/tmp/cctOFJNo.o: In function 
`SystemHessPatch::projectOnHessian(std::valarray<double> const&, 
std::valarray<double>&)':
/tmp/cctOFJNo.o(.text+0x0): multiple definition of 
`SystemHessPatch::projectOnHessian(std::valarray<double> const&, 
std::valarray<double>&)'
../SystemHessPatch.o(.text+0x0): first defined here
/tmp/cctOFJNo.o: In function `SystemHess::SystemHess()':
/tmp/cctOFJNo.o(.gnu.linkonce.t._ZN10SystemHessC2Ev+0x7): undefined reference 
to `vtable for SystemHess'
collect2: ld returned 1 exit status

---------------------------------------------------------------------------------
A couple questions, if anyone can answer them -- other than, why won't it 
work ;)

What could be causing the the 119 symbol to be present?  Why does it give 
"undefined reference to `vtable for SystemHess'" when that symbol is clearly 
there?  Why doesn't c++filt demangle 
"_GLOBAL__I__ZN15SystemHessPatch16projectOnHessianERKSt8valarrayIdERS1_"?

Any help, or pointers to more info would be greatly appreciated.

Thanks,
Craig

PS.

g++ version = 3.0.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]