2
我想使用boost :: lexical_cast將我的用戶定義類型轉換爲整數。 但是,我得到一個異常。我在想什麼?詞彙從用戶定義類型轉換爲int
class Employee {
private:
string name;
int empID;
public:
Employee() : name(""), empID(-1)
{ }
friend ostream& operator << (ostream& os, const Employee& e) {
os << e.empID << endl;
return os;
}
/*
operator int() {
return empID;
}*/
};
int main() {
Employee e1("Rajat", 148);
int eIDInteger = boost::lexical_cast<int>(e1); // I am expecting 148 here.
return 0;
}
我知道我總是可以使用轉換操作符,但只是想知道爲什麼詞法轉換在這裏不起作用。
日Thnx很多..愚蠢的錯誤:-)我的一部分。 – 2013-05-12 06:42:09
@RajatGirotra:很高興幫助:) – 2013-05-12 08:46:59