Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- class XPtr
- {
- private:
- T* p;
- public:
- XPtr(T* ptr) {
- p = ptr;
- }
- XPtr(const XPtr& ptr) {
- p = ptr.p;
- }
- T* operator&() {
- return p;
- }
- // The following declaration compiles but still
- // is it the correct way of declaring friend function?
- template<typename T>
- friend std::wstring getString(const XPtr<T>& p);
- };
- template<typename T>
- std::wstring getString(const XPtr<T>& p) {
- std::wstringstream ss;
- ss << L"{" << p.p;
- if (p.p != 0) { ss << L"," << *p.p; }
- ss << L"}";
- return ss.str();
- }
- using namespace Microsoft::VisualStudio::CppUnitTestFramework;
- namespace Microsoft {
- namespace VisualStudio {
- namespace CppUnitTestFramework {
- //Actually I would like to specialize for XPtr<T> instead of XPtr<int>,
- //how to do it?
- template<>
- static std::wstring ToString<XPtr<int> >(const class XPtr<int> & t)
- { return getString<int>(t); }
- }
- }
- }
- namespace TestRCPtr1
- {
- TEST_CLASS(UnitTest1)
- {
- public:
- TEST_METHOD(TestMethod6)
- {
- XPtr<int> pint1(new int(1));
- XPtr<int> pint2(pint1);
- Assert::AreEqual(&pint1, &pint2); // Test passes
- Assert::AreSame(pint1, pint2); // Test fails, see below for error message
- }
- };
- }
Add Comment
Please, Sign In to add comment