E
Ethan
class Base {
public:
virtual void foo (std::string& s) { // do crap here; }
};
class Derived : public Base {
// other crap
};
int main() {
Derived d;
std::string name("anyone");
d.foo (name); // ok
d.foo ("another one"); // error
d.foo (string("another one")); // error
}
g++ 3.4.6
when call the virtual function with temporary variable as parameters,
it always says:
not matching function for call too 'Derived::foo(std::string)'
candidates are: virtual void Base::foo(std::string&)
is it because no reference created for temporary variable? (in the 2nd
and 3rd cases);
I'd appreciate if someone can give a detailed explanation on this.
thanks!
public:
virtual void foo (std::string& s) { // do crap here; }
};
class Derived : public Base {
// other crap
};
int main() {
Derived d;
std::string name("anyone");
d.foo (name); // ok
d.foo ("another one"); // error
d.foo (string("another one")); // error
}
g++ 3.4.6
when call the virtual function with temporary variable as parameters,
it always says:
not matching function for call too 'Derived::foo(std::string)'
candidates are: virtual void Base::foo(std::string&)
is it because no reference created for temporary variable? (in the 2nd
and 3rd cases);
I'd appreciate if someone can give a detailed explanation on this.
thanks!