令人困惑的C++文法.

來源:互聯網
上載者:User

#include <iostream>
#include <cstddef> //for size_t
using namespace std;

//arr 13 run error in vs.net

/*template <class Key>
struct myhash
{
 void operator() ()
 {
  cout << "myhash<T>"  << endl;
 }
};

_STL_TEMPLATE_NULL struct myhash<char>
{
 void operator () ()
 {
  cout << "myhash<char>" << endl;
 }
};

_STL_TEMPLATE_NULL struct myhash<unsigned char>
{
 void operator() ()
 {
  cout << "myhash<unsigned char>" << endl;
 }
};

int main()
{
 myhash<long> t1;
 myhash<char> t2;
 myhash<unsigned char> t3;

 t1();
 t2();
 t3();

 return 0;
}
*/

//arr 12

/*class alloc
{
};

template <class T, class Alloc = alloc, size_t BuffSize = 0>
class mydeque
{
public:
 mydeque()
 {
  cout << "mydeque" << endl;
 }
};

template <class T, class Sequence>
class mystack;

template <class T, class Sequence>
bool operator == (const mystack<T, Sequence>& x, const mystack<T, Sequence>& y);

template <class T, class Sequence>
bool operator < (const mystack<T, Sequence>& x, const mystack<T, Sequence>& y);

template <class T, class Sequence = mydeque<T> >
class mystack
{
public:
 friend bool operator == <T>(const mystack<T>&, const mystack<T>&);
 friend bool operator < <T>(const mystack<T>&, const mystack<T>&);

 mystack()
 {
  cout << "mystack" << endl;
 }

private:
 Sequence e;
};

template <class T, class Sequence>
bool operator == (const mystack<T, Sequence>& x, const mystack<T, Sequence>& y)
{
 cout << "operator == " << endl;
 return true;
}

template <class T, class Sequence>
bool operator < (const mystack<T, Sequence>& x, const mystack<T, Sequence>& y)
{
        cout << "opeartor < " << endl;

 return false;
}

int main()
{
 mystack<int> x;
 mystack<int> y;

 cout << (x == y) << endl;
 cout << (x < y) << endl;

 return 0;
}*/

//arr 11
/*class alloc
{
};

inline size_t __deque_buf_size(size_t n, size_t sn)
{
 return n != 0 ? n : (sn < 512 ? size_t(512 / sn) : size_t(1));
}

template <class T, class Ref, class Ptr, size_t BuffSize>
struct __deque_iterator
{
 typedef __deque_iterator<T, T&, T*, BuffSize> iterator;
 typedef __deque_iterator<T, const T&, const*, BuffSize> cosnt_iterator;

 static size_t buffer_size()
 {
  return __deque_buf_size(BuffSize, sizeof(T));
 }
};

template <class T, class Alloc = alloc, size_t BufSize = 0>
class mydeque
{
public:
 typedef __deque_iterator<T, T&, T*, BufSize> iterator;
};

int main()
{
 cout << mydeque<int>::iterator::buffer_size() << endl;
 cout << mydeque<int, alloc, 64>::iterator::buffer_size() << endl;

 return 0;
}*/

//arr 10
/*class alloc
{
};

template <class T, class Alloc = alloc, size_t BufSize = 0>
class mydeque
{
public:
 mydeque()
 {
  cout << "deque" << endl;
 }
};

template <class T, class MySequence = mydeque<T> >
class mystack
{
public:
 mystack()
 {
  cout << "stack" << endl;
 }

private:
 MySequence c;
};

int main()
{
 mystack<int> x;

 return 0;
}*/

//arr 08
/*class alloc
{
};

template<class T, class Alloc = alloc>
class myvector
{
public:
 typedef T value_type;
 typedef value_type* iterator;

 template <class I>
 void insert(iterator position, I first, I last)
 {
  cout << "insert" << endl;
 }
};

int main()
{
 int ia [5] = {0, 1, 2, 3, 4};

 myvector<int> x;
 myvector<int>::iterator ite = NULL;

 x.insert(ite, ia, ia + 5);

 return 0;
}
*/

//arr06
/*class alloc
{
};

template <class T, class Alloc = alloc>
class myvector
{
public:
 void swap(myvector<T, Alloc>&)
 {
  cout << "swap()" << endl;
 }
};

template <class T, class Alloc>
inline void swap(myvector<T, Alloc>& x, myvector<T, Alloc>& y)
{
 x.swap(y);
}

int main()
{
 myvector<int> x, y;
 swap(x, y);
}
*/

//arr 05
/*template <class I, class O>
struct testclass
{
 testclass()
 {
  cout << "I, O" << endl;
 }
};

template <class T>
struct testclass<T*, T*>
{
 testclass()
 {
  cout << "T*, T*" << endl;
 }
};

template <class T>
struct testclass<const T*, T*>
{
 testclass()
 {
  cout << "const T*, T*" << endl;
 }
};

int main()
{
 testclass<int, char> obj01;
 testclass<int*, int*> obj02;
 testclass<const int*, int*> obj3;
}

*/
//arr03

/*template <typename T>
class testclass
{
public:
 static T _data;
};

int testclass<int>::_data = 1;
char testclass<char>::_data = 97;

int main()
{
 cout << "testclass<int>::_data = " << testclass<int>::_data << endl;
 cout << "testclass<char>::_data = " << testclass<char>::_data << endl;
}*/ 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.