2
爲什麼b.isEm()在最後一次調用b.isEm()
後沒有改變任何東西時會在不同的行上打印不同的東西?爲什麼b.isEm()在不同的行上打印不同的東西?
#include <iostream>
#include <string>
template <class T>
class Box
{
bool m_i;
T m_c;
public:
bool isEm() const;
void put(const T& c);
T get();
};
template <class T>
bool Box<T>::isEm() const
{
return m_i;
}
template <class T>
void Box<T>::put(const T& c)
{
m_i = false;
m_c = c;
}
template <class T>
T Box<T>::get()
{
m_i = true;
return T();
}
int main()
{
Box<int> b;
b.put(10);
std::cout << b.get() << " " << b.isEm() << std::endl;
std::cout << b.isEm() << std::endl;
}
的評估順序C++中的函數參數未指定... :-) – WhiZTiM
有關詳細信息:http://en.cppreference.com/w/cpp/language/eval_order – Danh