自学C++遇到的两个疑问,求指教
我知道有人会让我回去看书,但是我是用到别人的工程现学的,所以学习不系统,从头看起肯定来不及,所以只能边用边学
1、: Value() { setType(type); }表示什么意思?
/**
* Construct to a specific type
* @param value
*/
Value(Type type) : Value() { setType(type); }
表示什么意思? 我只知道:表示继承,但是一般都是继承一个类,这里怎么是个函数:Value() { setType(type); }? 而且函数没有返回值在函数名前面却没有void
这里也是:
template <typename T>
Value(const std::vector<T> &input) : Value(Type::Array)
{
// index
int i = 0;
// set all elements
for (auto &elem : input) setRaw(i++, elem);
}
表示继承 Value(Type::Array) 返回的类吗?
2、下面的尖括号表示什么?
vector<int>::iterator iter;
friend class HashMember<int>;
friend class HashMember<std::string>;
还有更复杂的,尖括号里面是个函数,它的返回值作为<>里的参数?
/**
* Friend functions which have to access that zval directly
*/
friend Value set_exception_handler(const std::function<Value(Parameters ¶ms)> &handler);
friend Value set_error_handler(const std::function<Value(Parameters ¶ms)> &handler, Error error);
3、operator
/**
* Comparison operators for hardcoded Value
* @param value
*/
bool operator==(const Value &value) const;
bool operator!=(const Value &value) const { return !operator==(value); }
bool operator< (const Value &value) const;
bool operator> (const Value &value) const { return value.operator<(*this); }
bool operator<=(const Value &value) const { return !operator>(value); }
bool operator>=(const Value &value) const { return !operator<(value); }
上面定义的操作operator都声明了返回值的类型,而下面这个却没有,为什么?
/**
* Cast to a number
* @return int32_t
*/
operator int16_t () const
{
return (int16_t)numericValue();
}
/**
* Cast to a number
* @return int32_t
*/
operator int32_t () const
{
return (int32_t)numericValue();
}
/**
* Cast to a number
* @return int64_t
*/
operator int64_t () const
{
return numericValue();
}
以上的代码出自:http://www.php-cpp.com/download 可以把工程下下来看,在value.h里面