odr.hpp
来自「[2005最新C++经典著作].C++ Programming.新手必看的学VC」· HPP 代码 · 共 49 行
HPP
49 行
// Copyright (C) 2004 Arkadiy Vertleyb// Use, modification and distribution is subject to the Boost Software// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)#ifndef ODR_HPP_INCLUDED#define ODR_HPP_INCLUDED#include <boost/spirit/typeof/typeof.hpp>void odr_test1();void odr_test2();// trying to cause ODR violation in a class templatetemplate<class T, class U>class sum_t{public: typedef BOOST_TYPEOF_TPL(T() + U()) result_type; sum_t(const T& t, const U& u) : m_sum(t + u) {} BOOST_TYPEOF_TPL(T() + U()) operator()() { BOOST_AUTO_TPL(result, m_sum); return result; }private: BOOST_TYPEOF_TPL(T() + U()) m_sum;};template<class T, class U>sum_t<T, U> make_sum(const T& t, const U& u){ return sum_t<T, U>(t, u);}// trying to cause ODR violation in a function templatetemplate<class T, class U>typename sum_t<T, U>::result_type sum(const T& t, const U& u){ BOOST_AUTO_TPL(result, t + u); return result;}#endif//ODR_HPP_INCLUDED
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?