Thread: Classes or Vectors?

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

    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
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    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
    Posts
    725
    Vectors are CONTAINERS, classes are OBJECTS, it's like comparing baskets and basketballs.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /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
    Location
    Portugal
    Posts
    89
    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.

    cheers

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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