how to call overloaded function in the same version of another in c++
You have to be in the scope of the class A
when defining the member functions outside the class. This can be done using A::
as shown below.
class A {
public:
inline A();
inline ~A();
QString insert(QString& id, QString& name, QString& email_id, QString& contact_id, QString& reg_num, Address addr, QUrl& urlToLocalFile );
QString insert(QString& id, QString& name, QString& email_id, QString& contact_id, QString& reg_num, Address addr, const QString& pathToLocalFile ); //note the const added for the last parameter
}; //added missing semicolon here
//note the A:: used below
inline QString A::insert(QString& id, QString& name, QString& email_id, QString& contact_id, QString& reg_num, Address addr, QUrl& urlToLocalFile ) {
this->insert(id, name, email_id, contact_id, reg_num, addr, urlToLocalFile.toLocalFile());
}
//note the const added in the last parameter
inline QString A::insert(QString& id, QString& name, QString& email_id, QString& contact_id, QString& reg_num, Address addr, const QString& pathToLocalFile ) {
/*some tasks*/
}
Additionally you're missing a semicolon ;
after class definition.
Also, note that we cannot bind non-const lvalue reference to an rvalue. So the last parameter of the second insert
member function should be const QString& pathToLocalFile
instead of QString& pathToLocalFile
The problem is calling by reference.
Converting QString&
to const QString&
gets the job done.
We may not be able to have string& a = b
and then string& c = a
to achieve this. We must use pointers or constant type.
That is, of course, according to my understanding and seems to work.
class A {
public:
inline A();
inline ~A();
QString insert(const QString& id, const QString& name, const QString& email_id, const QString& contact_id, const QString& reg_num, Address addr, const QString& pathToLocalFile );
QString insert( const QString& id, const QString& name, const QString& email_id, const QString& contact_id, const QString& reg_num, Address addr, const QUrl& urlToLocalFile );
};
inline QString A::insert(const QString &id, const QString &name, const QString &email_id, const QString &contact_id, const QString ®_num, Address addr, const QUrl &urlToLocalFile) {
return this->insert(id,name,email_id,contact_id,reg_num,addr,urlToLocalFile.toLocalFile());
}
inline QString A::insert(const QString &id, const QString &name, const QString &email_id, const QString &contact_id, const QString ®_num, Address addr, const QString &pathToLocalFile) {
}