문자열 클래스에서 공개적으로 상속 된 하나의 새 클래스를 만들었습니다. 파생 클래스에서 <
(보다 작음) 연산자를 오버로드하고 싶습니다. 하지만 오버로드 된 함수로부터 부모 클래스 인 <
연산자를 호출해야합니다. 이 함수를 호출하는 구문은 무엇입니까? 가능한 경우 멤버 함수로 연산자를 구현하고 싶습니다.오버로드 된 함수에서 부모 클래스 멤버 함수를 호출하는 방법은 무엇입니까?
자바에서는 super
이라는 키워드가 있습니다.
내 코드는 아래와 같습니다.
bool operator<(const mystring ms)
{
//some stmt;
//some stmt;
return string::operator<(ms);
}
아아, std::string
때문에 operator<
작동하지 않는 멤버 함수되지 않은 : 당신이 재미있는 이름을 가진 단지 함수 것을 깨닫게 경우 기본 클래스 operawtor를 호출
#include<iostream>
#include<string>
using namespace std;
class mystring:public string
{
bool operator<(const mystring ms)
{
//some stmt;
//some stmt;
//call the overloaded <(less than)operator in the string class and return the value
}
};
가'string''표준 : string'? –
예 std :: string –
링크를 제공해 주셔서 감사합니다. 부모 클래스에서보다 작음 연산자를 호출하는 구문이 필요합니다. –