Thread: Classes or Vectors?

  1. #1
    C / C++
    Join Date
    Jan 2006
    The Netherlands

    Classes or Vectors?

    When should I use Vectors/Classes? They can both hold methods/multiple datatypes.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  2. #2
    Join Date
    Jul 2005
    When you feel that they would make your life easier.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Vectors are CONTAINERS, classes are OBJECTS, it's like comparing baskets and basketballs.
    #include <stdio.h>
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  4. #4
    #define WORLD "sad place" LinuxCoder's Avatar
    Join Date
    Mar 2006
    Quote Originally Posted by Ideswa
    They can both hold methods/multiple datatypes.
    They are different in the way that vectors are merely containers, they have a collection of objects and the only methods they have are the ones used for traversing/manipulating that collection of objects. With classes you define new objects by defining the objects methods and data members. With vectors you can't define anything. In the end it all comes down to the fact that a vector object is an instance of a vector class.


  5. #5
    Registered User
    Join Date
    Jan 2005
    >> They can both hold methods/multiple datatypes.

    vectors cannot hold multiple datatypes at the same time, classes can have many different types as members. vectors cannot hold methods other than perhaps function pointers or function objects, classes can of course have many different member functions with different signatures.

    They are completely different tools.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes and vectors
    By izuael in forum C++ Programming
    Replies: 10
    Last Post: 11-27-2006, 04:19 PM
  2. Vectors and custom classes
    By cunnus88 in forum C++ Programming
    Replies: 16
    Last Post: 05-12-2006, 05:11 AM
  3. Vectors + Classes = Confusing
    By Epo in forum C++ Programming
    Replies: 59
    Last Post: 12-18-2004, 04:42 PM
  4. vectors and classes
    By jimothygu in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 07:53 PM
  5. How To use vectors for custom classes
    By johnnyd in forum C++ Programming
    Replies: 14
    Last Post: 03-25-2003, 10:04 PM