|
From: Per W. <pw...@ia...> - 2004-01-31 13:18:02
|
Maya - try compiling your examples :-)
This is a construct that is affected by language.
In C:
struct Human {
...
};
Require you to always declare your variables as:
struct Human a_human;
In C++ - together with the addition of the class keyword - you can get
away with:
struct Human {
...
};
Human a_human;
or
class Human {
public:
...
};
Human a_human;
So basically:
typedef struct Human {
...
} _Human;
declares a structure named Human, and typedef this struct to the name
_Human.
In C, you can then declare a variable as either of:
struct Human a_human; /* referencing the name of the struct */
_Human a_human; /* referencing type typedef name */
while in C++ it doesn't matter. It is even possible to define the data
type as:
typedef struct Human {
..
} Human;
i.e. same name for the struct declaration and for type typedef.
/Per W
On Sat, 31 Jan 2004, Maya wrote:
> In the first one you have declared a struct named _Human and
> instantiated it right after the declaration with name Human. In your
> program you can just say for instance: " Human.height = 1.70 " and it
> will work
> Here is another example:
> typedef struct _Human {
> int height;
> }Human;
>
> int main(){
> std::cout << "The Human Project" << std::endl;
> std::cout << "How tall are you " ;
> std::cin >> Human.height;
> return 0;
> }
>
> In the second example you have declared a struct named Human, but has
> not yet been instantiated.
> Your code would look something like this
>
> struct Human {
> int height;
> };
> int main(){
> Human human; // Instantiating the Human struct
> std::cout << "The Human Project" << std::endl;
> std::cout << "How tall are you " ;
> std::cin >> human.height; // <<==
> return 0;
> }
> Which one is better? it depends on the program you are working on, really!
>
> Hava a good one!
> coo...@ho... wrote:
>
> > what is the difference between these two
> >
> > typedef struct _Human
> > {
> > int height;
> > }Human;
> >
> > struct Human
> > {
> > int height;
> > };
> >
> >
> > and in the first one, what does 'Human' mean at the end? In both
> > structs u can declare a Human type, even without the Human thing at
> > the end in the first one
> >
> > _________________________________________________________________
> > STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> > http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
> >
> >
> >
> >
> > -------------------------------------------------------
> > The SF.Net email is sponsored by EclipseCon 2004
> > Premiere Conference on Open Tools Development and Integration
> > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> > http://www.eclipsecon.org/osdn
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> --
>
> FYI
> http://www.astro.umd.edu/~marshall/abbrev.html
>
> E-Mail Policy
> http://www.vif.com/users/escalante/Email_Policy.html
>
> * You cannot exercise your power to a point of humiliation.
> - Jean Chretien
>
> * The media's the most powerful entity on earth. They have the
> power to make the innocent guilty and to make the guilty
> innocent, and that's power.
> - Malcom X
> * "Innocent until proven guilty", no... not in Canada!!
>
>
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration
> See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> http://www.eclipsecon.org/osdn
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|