c++ code interperters


hi all...

i'm looking for a utility that can interpret lines of c++ into plain english...

for example in this class definition how do i read the constructor line?
1
2
3
4
5
6
7
class ObdImage
{
public:
    ObdImage(string p_id, string p_path) : id(p_id), path(p_path) {}
    string id;
    string path;
};



thanks..

Last edited on
ok so i found cdecl. which apparently is great with pointers and such but i still don't know how to read the ObdImage function declaration above. when given to cdecl the line:
ObdImage(string p_id, string p_path) : id(p_id), path(p_path) {}
returns:

syntax error bad character ':' bad character '{' bad character '}'

on the site cdecl.org

or when using the cdecl command line tool

cdecl> explain ObdImage(string p_id, string p_path) : id(p_id), path(p_path) {}
syntax error
bad character ':'
bad character '{'
bad character '}'
cdecl>
Last edited on
I think that the example you give is c++11 native code... so it's possible that the program you have isnt fit to understand C++11 native code, so maybe you should look for an updated version of one of these apps!
No code in this topic is C++11, all will compile under C++03 or C++98. The problem is taking the line out of context - the software does not have the context it needs to understand the code.

Alternatively, you could just ask us human beings (and me an AI) instead of trying to find a utility for it.
Last edited on
what don't you understand about the code?
the member variables of object of class ObdImage get initialized with the values passed as parameters; it's a conctructor too!
Last edited on
in the constructor declaration ObdImage(string p_id, string p_path) : id(p_id), path(p_path) {}
is the part : id(p_id), path(p_path)
some sort of in-line variable initialization?! if so what's the reasoning?
is it equivalent to:
1
2
3
4
5
6
7
8
class ObdImage
{
public:
    ObdImage(string p_id, string p_path) {
           string id = p_id;
           string path = p_path;
    }
};

?

or
1
2
3
4
5
6
7
8
9
10
11
class ObdImage
{
public:
    string id, path;
    ObdImage(string, string);
};

ObdImage::ObdImage(string p_id, string p_path) {
      string id = p_id;
      string path = p_path;
}

?
is the part : id(p_id), path(p_path) some sort of in-line variable initialization?!

Yes. It's called an initialiser list. It's preferable to your second code example, because it initialises those data members as they're constructed, rather than assigning values to them after construction.
Topic archived. No new replies allowed.