Are stucts faster than classes for linked lists?
I think stucts are easier to initialize becuase you dont need a constructor but its easier to have functions inside a class.
Also its a bit simpler to point to a struct than a class.
Are stucts faster than classes for linked lists?
I think stucts are easier to initialize becuase you dont need a constructor but its easier to have functions inside a class.
Also its a bit simpler to point to a struct than a class.
structs are just classes with all public data. Neither is faster than the either. I don't see how its easier to point to a struct than a class.
I thought structs were better since they came from the C language. Someone once told me that C is better than C++. Oh well, veteran oppinions could mis guide you sometimes
C is not better than C++. C++ is not better than C. They are different, and each has it's own strong points. You don't see many new games being made in C, and you don't see any operating systems written in C++.
I think structs are easier to understand and write code with. I don't like classes too much, so I personally use structs for linked lists. Sometimes classes make things more complicated than they need to be.
c++ structs can have all the advanced features of c++ classes. They a basicly the same.
But we use them differently.
struct's and classes...mmm
I see no real diff if you are using c++, other than (already mentioned) struct's default data to public and classes default them to private. In c++ both can contain method's. If Im wrong correct me.
But personally it comes down to personal preference.
kwigibo
I don't think classes default to private, but they do have the ability to store private data. Structs cannot hold private data.
Actually classes are supposed to default to private access, and structs are and do default to public access.
"only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein
Do this:
- define a structure
- declare an array of at least 2 elements
- in the program print out the addesses of each element in each structure
then:
- define a class
- declare an array with atleast 3 elements of the class
- in the program print out the address of each element in each class
From this, you should see that at run time the structure and the class are treated identically. The performance issues will be in function calls and how deep they are nested which you can control in the design.
sigma
Yes i see what you mean.
I guess the main difference is that a class uses a constuctor making the declaration different unless you declare all of its members public so you have dirrect access to them.
My big problem is finding a way to link a four dimensional list dynamically.
Currently Im doing it directly which would become very difficult when I add more elements to the list.
Well here is some advice, STRUCTS and CLASS's are different, yes they are, if you are using structs you typically use strict C code. (in professional code you do)
structs then cant have constructors or destructors, (HUGE Difference) and cannot have multipul inheritence.
now thats makes structs and class's different.
for linked lists tho, use structs, since its typically what is used in professional code.
by the way class's are defaulted to private, and structs are defaulted to public.. also structs can have private data members.
the guy who said they cant, do u code much?
LB0: * Life once school is done
LB1: N <- WakeUp;
LB2: N <- C++_Code;
LB3: N >= Tired : N <- Sleep;
LB4: JMP*-3;
I didn't know structs could have private data. I code a fair amount, you can check the CVS linked from my sig to see the code I've written.
Yeah, but I'm just learning c++ and I'm a sophomore in high school. I guess my teacher is wrong...
If you need a constructor, it would be better form to use a CLASS.
As a matter of preference, if you are going to embed functions into your objects- use a CLASS - for straight data members it's okay to use a struct.
How are u able to inherit from a STRUCT is something I've never heard of- inheritance and polymorphism are one of the major improvements of C++ over C.
I've never heard of STRUCTS holding private data and don't think it is possible unless someone wishes to show me otherwise.
Last thing, I don't think that CLASS's are defualted to private, they are defualted to public unless otherwise noted. This is becuase a constructor is public and if you were to create data member or member functions inside the CLASS without using specifications the access would be public. All functions and members would be accessible from outside the class.
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."