what excactly are atrributes in a class?


so we got a assignment from school and we have to create a class but I don't quite understand what they mean with attributes.


[ #include <iostream>

class Field
{
public:
enum FieldType {GRASS, WATER}
};
]
now it says this but I really have no Idea what I should do , does anyone have an Idea what our lecturers mean?

attributes
type_
The type of field as FieldType
Last edited on
Hello king2105,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

It looks like you may have started to use a code tag, but got it wrong.

In the code you have:

"class" is a type like "int", "double", "char" or "std::string" along with others.
"Field" is the name of the class. Notice that the class name starts with a capital letter. I like to use a capital letter at the beginning of "class", "struct" and "function" names to make them different than variable names where I use a lowercase letter.

In the public section "enum" is a type "FieldType", which I would have done as "fieldType" looking at this more as a variable name, which is the name used to reference or use the "enum" names. What is between the {}s are the names or attributes that are representations of numbers which start at zero and increase by one with every new name. Or you can assign a different number to each name or just a new starting number to the first name.

Another way of looking at attributes also referred to as parameters is what is between the ()s of a function call.

If I have anything wrong someone is likely to correct me.

You may try a search here on attributes and see what you can find or try Google.

Hope that helps,

Andy
Topic archived. No new replies allowed.