When should I use Vectors/Classes? They can both hold methods/multiple datatypes.
When should I use Vectors/Classes? They can both hold methods/multiple datatypes.
Operating Systems:
- Ubuntu 9.04
- XP
Compiler: gcc
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.
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;}
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.Originally Posted by Ideswa
cheers
>> 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.