10

I know that the naming convention for an interface is something like IName. But what if I am creating an abstract class?

Should I also write an I in front of the class name?

3
  • It sounds a bit confuse for me. What do you mean by abstract and interface? In C++ a class is abstract if it has at least one pure virtual function. An interface class is usually such a - typically, but not necessarily abstract - class, that is primarily for hiding implementation details in derived classes and being used on public interfaces.
    – jmihalicza
    Commented May 7, 2013 at 23:11
  • 8
    The I prefix is a Microsoftism (for COM and .NET), not a C++ naming convention per se.
    – dan04
    Commented May 7, 2013 at 23:13
  • In java and c# you can see directly if the class is abstract or if it is an interface. I already saw several times the I prefix so I adapted it. I just want to make it clear to other developers that this class is abstract or and interface. I probably use the I prefix for abstract classes too.
    – Maik Klein
    Commented May 7, 2013 at 23:15

3 Answers 3

11

As opposed to Oracles Java coding conventions, there is no "The" naming convention for C++.

  • If you are working on a project for some company you should follow their naming conventions. If there are no documented conventions - look around the code base and try to follow the swarm, consistency is the key.

  • If you are starting something on your own, many find google's c++ coding conventions as a good start.

6
  • 14
    Hmm, I don't know any C++ developers who think Google's conventions are good general guidelines. They're great for Google, but they have to work within constraints that are not universally applicable.
    – Cody Gray
    Commented May 7, 2013 at 23:47
  • 2
    I wrote that it was a good start, not the holy grail. Are there any good conventions that are universally applicable? Feel free to link to other guidelines.
    – Zelix
    Commented May 7, 2013 at 23:56
  • 4
    That's precisely the point: I and many others do not think it is a good start. It contains a lot of bad, inapplicable, and misleading advice.
    – Cody Gray
    Commented May 7, 2013 at 23:57
  • Feel free to link to other guidelines. I am curious.
    – Zelix
    Commented May 7, 2013 at 23:59
  • Dead link to Google's coding conventions. Closest match alive today: google.github.io/styleguide/cppguide.html#Naming Commented Jun 20, 2016 at 6:11
7

If you are trying to adhere to a specific naming convention, please name it. As the other answer explains, there is no global "C++ Rule" regarding naming conventions.

If you are using Hungarian notation, I believe that the convention is indeed to prefix 'I' as you did for 'IName'.

Note: Whilst there is no "interface" as such in C++, you can define classes with only pure virtual methods and no member variables.

0
3

There is no such thing as a global naming convention. At the time you know by what naming convention, you can look up the answer in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.