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

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!

Related

Overloaded methods - (Error C2664: Cannot convert from vector<T> to T)

I'm trying to call an overloaded method from the other overloaded member. I am getting an error C2664: Cannot convert argument 2 from std::vector<PK_BODY_T*, std::allocator<_Other>> to PK_BODY_T
Code:
std::vector<PK_BODY_t*> FillHoles(std::vector<std::vector<PK_EDGE_t>> holes, PK_BODY_t inputBody)
{
std::vector<PK_BODY_t*> vectorBodies;
PK_BODY_t *pointerInputBody = new PK_BODY_t(inputBody);
vectorBodies.push_back(pointerInputBody);
std::vector<PK_BODY_t*> returnVector;
returnVector = FillHoles(holes, vectorBodies); //<-- ERROR HERE. Calling overloaded method.
delete pointerInputBody;
return returnVector;
}
/* overloaded version of FillHoles
*/
std::vector<PK_BODY_t*> FillHoles(std::vector<std::vector<PK_EDGE_t>> holes, std::vector<PK_BODY_t*> inputBody)
{
//...
std::vector<PK_BODY_t*> fillHoleOutput = FillOneHole(currentBody, currentHole);
return fillHoleOutput;
}
It appears as if the first method is trying to call itself here, instead of the second overloaded method. How do I force it to use the second method?
You did not show how the functions are declared and in what scopes whether one function hides other function.
But in any case just declare the second overloaded function inside the first overloaded function
std::vector<PK_BODY_t*> FillHoles(std::vector<std::vector<PK_EDGE_t>> holes, PK_BODY_t inputBody)
{
std::vector<PK_BODY_t*> FillHoles(std::vector<std::vector<PK_EDGE_t>> holes, std::vector<PK_BODY_t*> inputBody);
//...
C++ files are compiled from top to bottom. From the vantage point of the top method, it cannot 'see' the second method, because it has not been compiled yet (as the second method is after the first method).
You must either declare methods in a header .h file, or forward declare the methods at the top of the .cpp file.
http://www.learncpp.com/cpp-tutorial/19-header-files/
http://www.learncpp.com/cpp-tutorial/17-forward-declarations/

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 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.

regarding encryption method

i am using encrypt function of cryptography api(fun declared as virtual)
//fun declaration
TBool EncryptL(const TDesC8 &aInput, TDes8 &aOutput);
//function calling
TBuf8<10> text;
TBuf8<10> cipher;
text.Copy(_L("Hello"));
iEncryptor.EncryptL(text,cipher); it shows error expression syntax error
//fun definition
TBool CRSAAlgo::EncryptL(const TDesC8 &aInput,TDes8 &aOutput)
{
if(iEncryptor)
{
TInt len = iEncryptor->MaxInputLength();
}
}
i want to know what is exact problem
The main issue here, the reason your compiler complains is that you are using iEncryptor as an object or a reference, while it probably is a C++ pointer.
To move to the next stage, try using:
iEncryptor->EncryptL(text,cipher);
As you did not post the exact error message you get from the compiler I have to guess.
I assume the problem is that the EncryptL function you show expects to get arguments of type TDesC8 and you pass a TBuf8<10> to it. Unless TDesC8 were a typedef to TBuf8<10> these are different and therefore for the compiler incompatible types.
Ypou are also using iEncryptor once as a pointer: iEncryptor->MaxInputLength(); and at the location where you see the error as an object: iEncryptor.EncryptL(text,cipher);. Only one form can be correct. As we don't have more code from you I don't know which, but given the fact that the latter has the error I suspect the latter.