code_junkie

c++ array declaration in a header

Nov 12th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Test {
  2. int a[];
  3. public:
  4. Test(int size);
  5. };
  6.  
  7. Test::Test(int size) {
  8. a[size]; // this is wrong, but what can i do here?
  9. }
  10.  
  11. class Test {
  12. int *a;
  13. public:
  14. Test(int size) {
  15. a = new int[size];
  16. }
  17. ~Test() { delete [] a; }
  18. private:
  19. Test(const Test& other);
  20. Test& operator=(const Test& other);
  21. };
  22.  
  23. class Test
  24. {
  25. std::vector<int> a;
  26. public:
  27. Test(std::size_t size):
  28. a(size)
  29. {}
  30. };
  31.  
  32. template <int N> class Test {
  33. int a[N];
  34. public:
  35. Test() { }
  36. };
  37.  
  38. Test<5> test;
  39. Test<40> biggertest;
  40.  
  41. std::vector<char> vec(10);
  42. memset(&vec[0], 0, vec.size());
Add Comment
Please, Sign In to add comment