Simple entity class

What's the proper way of creating a simple entity class in C++ whose only purpose is to store publicly accessible variables? In Java, for example, I'd do something like this...

1
2
3
4
5
6
7
public class Properties{
	public int port;
	public String url;
        //etc...

	public Properties() {}
}


Would I only need a header file for something like this in C++?
Last edited on
Use structs: http://www.cplusplus.com/doc/tutorial/structures/
you can use classes for the same purpose too btw http://www.cplusplus.com/doc/tutorial/classes/
Where do I declare the struct if it is to be shared across multiple source files or classes?
sorry, forgot to answer, your 2nd question :)
Would I only need a header file for something like this in C++?

Yes. and you can include the header in any source files where you need to use your structs

edit: here's an article on header files on this forum: http://www.cplusplus.com/forum/articles/10627/
Last edited on
Ah, I see. What if I needed to declare a variable array inside the struct? I've googled around on this subject but haven't found anything useful so far.

This is what I've tried so far...

1
2
3
4
5
6
7
8
9
10
struct Properties
{
	string test[];
};

int main()
{
	Properties p;
	p.test = {"abc"};
}
Use std::vector instead of arrays: http://www.cplusplus.com/reference/stl/vector/
Topic archived. No new replies allowed.