error: no matching function for call to - c++

i want to use a method of anothre class in another one,but i get error below,whats the problem?
TIA
error: no matching function for call to ‘PositionInfo::PositionInfo()’
here is my code:
PositionInfo Pos;
double metr=Pos.GetBallDistToTeammate(5);
and PositionInfo.h class is:
PositionInfo(WorldState *pWorldState, InfoState *pInfoState);
and PositionInfo.cpp class is:
const double & GetBallDistToTeammate(Unum unum) const { Assert(unum > 0); return GetBallDistToPlayer(unum); }

Default constructor PositionInfo::PositionInfo() { /* code */} is missing in your cpp file.

error: no matching function for call to ‘PositionInfo::PositionInfo()’
This seems like someone tries to call a default constructor for the class, but the compiler cannot find one.

Related

No Matching function to call C++

I have 2 classes TreeManager and TreeProducerBase. I am getting an error in passing an object of TTree( which is a class to make trees) to a function in TreeProducerBase from TreeManagerconstructor.
Note : I have defined tree as
TTree *tree_
Function call :
tpb.initialize(&tree_);
Here, tpb is an object of TreeproducerBase class.
This is the function that is being called.
void initialize(TTree &tree_)
It shows the error as follows:
error: no matching function for call to 'TreeProducerBase::initialize(TTree*&)'
Where am I doing wrong?
You are trying to pass pointer-to-pointer-to-TTree to a function that expects reference-to-TTree. Try redeclare it like
void initialize(TTree* &tree_);
Invokation will look like
tpb.initialize(tree_);
And then you can initialize outer pointer via simple assignment:
void initialize(TTree* &tree_) {
tree_ = new TTree(); // or smth else
}

error: no matching function for call

I'm calling a one argument constructor and I'm getting an error that seems to read that I'm calling a no argument constructor (which doesn't and shouldn't exist).
This is the error I'm getting
g++ -g -c predictor.C
In file included from predictor.C:5:
PHT.C: In constructor 'PHT::PHT(int)':
PHT.C:5: error: no matching function for call to'TwoBitPredictorTable::TwoBitPredictorTable()'
TwoBitPredictorTable.C:5: note: candidates are: TwoBitPredictorTable::TwoBitPredictorTable(int)
predictor.h:25: note: TwoBitPredictorTable::TwoBitPredictorTable(const TwoBitPredictorTable&)
Here is the constructor call on line 5 in PHT.C
PHT::PHT(int rows)
{
predictor = TwoBitPredictorTable(rows);
}
The class definition for PHT is:
class PHT
{
TwoBitPredictorTable predictor;
public:
PHT(int rows);
bool update(unsigned int pc, unsigned int ghr, bool outcome);
bool getPrediction(unsigned int pc, unsigned int ghr);
};
The idea is to make a class PHT which wraps a TwoBitPredictorTable.
I'm pretty new to C++, but after hours of searching for an answer, I'm asking for your help. Thanks in advance :)
You need to call the constructor in the initialization list. What you have now is equivalent to:
PHT::PHT(int rows) :
predictor() // <-- error, no default constructor
{
predictor = TwoBitPredictorTable(rows);
}
Instead:
PHT::PHT(int rows) :
predictor(rows)
{
}
Looks like TwoBitPredictorTable has no default constructor. You should use the initializer list to construct TwoBitPredictorTable during PHT construction.
PHT::PHT(int rows) : predictor(rows)
{
}
Should look something like this.

compiler adding references operator

I try to call a class function from another class an I get something absolutely weird
all parameters are treated as references , and i cant see why the compiler threat this as a special case
class AbstractModulation
{
public:
virtual bool isValidMatch(
FOLTerm* toMatch,
std::set<FOLVariable>* toMatchVariables,
FOLTerm* possibleMatch,
unordered_map<FOLVariable, FOLTerm*>* substitution)=0;
...
this line:
abstractModulation->isValidMatch(toMatch, toMatchVariables,(FOLTerm*) variable,substitution)
causes this error (see the & character added to each parameter..wtf?):
AbstractModulation.cpp:105:104: error: no matching function for call to ‘AbstractModulation::isValidMatch(FOLTerm*&, std::vector<FOLVariable>*&, FOLTerm*, std::unordered_map<FOLVariable, FOLTerm*>*&)’
candidate:
AbstractModulation.h:44:7: note: bool AbstractModulation::isValidMatch(FOLTerm*, std::set<FOLVariable>*, FOLTerm*, std::unordered_map<FOLVariable, FOLTerm*>*)
and here are the objjects pointers from the calling class
class IdentifyCandidateMatchingTerm : public FOLVisitor
{
private:
FOLTerm* toMatch;
vector<FOLVariable>* toMatchVariables;
FOLTerm* matchingTerm;
unordered_map<FOLVariable, FOLTerm*>* substitution;
please help me out, this is really weird...
You have defined your function taking std::set<FOLVariable>* variable but you try to call it with std::vector<FOLVariable>*.
error: no matching function for call to
‘AbstractModulation::isValidMatch(FOLTerm*&, std::vector<FOLVariable>*&,
^^^^^^^^^^^
But definition is
virtual bool isValidMatch( FOLTerm* toMatch, std::set<FOLVariable>*
^^^^^^^^
This clearly explains what is going on. Double check how and where you are calling this method.

C++ - Smart Pointers - Passing derived class shared pointer to base through template

I have the following and having difficulty resolving the error please help.
i have the following class as template definition somewhere.
template<class ConcreteHandlerType>
class SomeAcceptor: public ACE_Acceptor<ConcreteHandlerType, ACE_SOCK_Acceptor>
In some other file, i initialize this class in the constructor
class initialize {
typedef SomeAcceptor<BaseClassSomeHandler> baseAcceptor_t;
typedef SomeAcceptor<DerivedClassSomeHandler> derivedAcceptor_t;
boost::shared_ptr<baseAcceptor_t;> mAcceptor;
boost::shared_ptr<derivedAcceptor_t;> mDerivedAcceptor;
bool HandleAcceptNotification(BaseClassSomeHandler& someHandler);
initialize() : mAcceptor(0), mDerivedAcceptor(new DerivedAcceptor_t) {
mAcceptor->SetAcceptNotificationDelegate(fastdelegate::MakeDelegate(this, &initialize::HandleAcceptNotification));
}
}
Error i get is
error: no matching function for call to `boost::shared_ptr<SomeAcceptor<BaseClassSomeHandler> >::shared_ptr(int)'common/lib/boost_1_39_0/boost/smart_ptr/shared_ptr.hpp:160: note: candidates are: boost::shared_ptr<SomeAcceptor<BaseClassSomeHandler> >::shared_ptr(const boost::shared_ptr<SomeAcceptor<BaseClassSomeHandler> >&)
common/lib/boost_1_39_0/boost/smart_ptr/shared_ptr.hpp:173: notboost::shared_ptr<T>::shared_ptr() [with T = SomeAcceptor<BaseClassSomeHandler>]
I also tried overloading the function with
bool HandleAcceptNotification(DerivedClassSomeHandler& someHandler);
but because mAcceptor is of type SomeAcceptor BaseClassSomeHandler, i get this error, but to fix this.
I guess i need to cast it somehow, but how to do it?
i tried doing like below inside the constructor and it didn't work
initialize() : mAcceptor(0), mDerivedAcceptor(new DerivedAcceptor_t) {
mAcceptor = mDerivedAcceptor; // Error here
mAcceptor->SetAcceptNotificationDelegate(fastdelegate::MakeDelegate(this, &initialize::HandleAcceptNotification));
}
From your code, it looks like you want mAcceptor to be assigned NULL (0), if that is the case you don't need to initialize it at all, as the default constructor will take care of that. But, since you call a function on that (NULL) pointer immediately, its not immediately clear exactly what you want to do.
If you want mAcceptor and mDerivedAcceptor to point to the same (shared) object and assuming DerivedClassSomeHandler is derived from BaseClassSomeHandler, this is a situation where you should use boost::shared_static_cast, as described here.
There's also some good information in this apparently related question.
The error is due to the mAcceptor(0) in
initialize() : mAcceptor(0), mDerivedAcceptor(new DerivedAcceptor_t) {
mAcceptor->SetAcceptNotificationDelegate(fastdelegate::MakeDelegate(this, &initialize::HandleAcceptNotification));
}
The smart_ptr default constructor assigns the wrapped ptr to NULL, so leave out mAcceptor(0) from the initialization list.
boost::shared_ptr<SomeAcceptor<BaseClassSomeHandler> >::shared_ptr(int)
It's yelling at you that there's no constructor that accepts an int.
Just use: mAcceptor()

error: no matching function for call to

I am getting the "no matching function for call to error" in my code. The code is creating instances of one class in the constructor of another class.
The code is as follows:
inline DiscriminatorContainer::DiscriminatorContainer(ushort id, FebPtr feb):
m_id(id), m_feb(feb), m_discriminators(new Discriminators()) {
//make discriminators
for (ushort i = 0; i <kNDiscriminators; ++i){
DiscriminatorPtr dsc = DiscriminatorPtr(new Discriminator(i, this));
m_discriminators->push_back(dsc);
}
}
inline Discriminator::Discriminator(ushort id, DiscriminatorContainerPtr dc, double threshold) :
m_id(id), m_threshold(threshold),
m_nhits(0), m_dc(dc)
{
init();
}
These constructors are actually in two different header files, but I included both for completeness.
I get the error
../src/DiscriminatorContainer.h:50: error: no matching function for call to `Minerva::Discriminator::Discriminator(ushort&, Minerva::DiscriminatorContainer* const)'
../src/Discriminator.h:24: note: candidates are: Minerva::Discriminator::Discriminator(const Minerva::Discriminator&)
../src/Discriminator.h:61: note: Minerva::Discriminator::Discriminator(ushort, Minerva::DiscriminatorContainerPtr, double)
about the line that goes DiscriminatorPtr dsc = ....
I know that such an error usually means I've got a wrong data type somewhere, but I can't figure out where it could be?
Typical case of "read the error message more carefully".
It's telling you that you are trying to call the function with the signature Minerva::Discriminator::Discriminator(ushort&, Minerva::DiscriminatorContainer* const)
but there only exists two other constructors
Minerva::Discriminator::Discriminator(const Minerva::Discriminator&)
Minerva::Discriminator::Discriminator(ushort, Minerva::DiscriminatorContainerPtr, double)
So just check the call to the constructor. You probably forget one argument.
new Discriminator(i, this) does not match any constructors.
Edit
Well, inlining doesn't affect default arguments so you must have made a mistake somewhere else!