-1

I am new to c++ and am told to understand a c++ code related to my project. I'm not sure what this means. car is a class car_CallBack is defined in some top level directory(as i'm told). I'm not clear about the first 3 lines of code. I believe the 4th line of code to be a constructor. Please provide me some insight as to what the snippet may mean...

struct model_ares : car,
public car_CallBack,
module_if::model_ares
{
  model_ares(const char *model_name);
  void init();
  void start_test();
RoyOneMillion
  • 225
  • 2
  • 10
  • If you are new to C++, then your first priority should be to read a good book. See here: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/4891093 – JBentley Oct 21 '13 at 15:04

2 Answers2

3

What is means is that model_ares is a type that inherits publicly from car, car_CallBack and module_if::model_ares, and has a public converting constructor and two other public member functions.

In C++, class and struct are essentially the same. Default inheritance and members are public for struct and private for class. That is the only difference. You can express exactly the same types using either.

Your code is completely equivalent to

class model_ares : public car, 
                   public car_CallBack, 
                   public module_if::model_ares
{
 public:
  model_ares(const char *model_name);
  void init();
  void start_test();
};
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • do you mean that the two model_ares in "model_ares" and "module_if::model_ares" are different?? Also what do you mean by public converting constructor here ie whose private variables are being made public? – RoyOneMillion Oct 21 '13 at 14:45
  • @RoyOneMillion yes, they should be different types. The public converting constructor is `model_ares(const char *model_name);`. – juanchopanza Oct 21 '13 at 14:47
  • If it inherits from 3 sources( car, car_CallBack and module_if::model_ares), what may be the reason why access modifier(public) required only before car_CallBack? – RoyOneMillion Oct 21 '13 at 14:50
  • @RoyOneMillion it is not required. As I explained in my answer, inheritance is `public` by default in `struct`. Whoever wrote `public` there was probably just doing it for fun. – juanchopanza Oct 21 '13 at 14:51
0

In C++, struct is same as class. Only one difference is that default visibilityof struct members is public, and private for classes.

Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61