2

When I was learning C++ using JetBrains CLion IDE, I noticed there are comments in the code that looks different from Ctrl + / comments. Those comments have a pen and book gutter icon (documentation).

These only appear if I select "add onboarding tips" while creating a new project. And I can add tips by using // TIP in the beginning of the comment. But I can't replicate this in other project where I did not select the "onboarding tips". Also, I could not replicate this in the same project with enabled "onboarding tips" in separate C++ source files. I have done some research but no luck.

Example images:

Documentation Comment

Set certificate passphrase

// TIP See CLion help at \<a
// href="https://www.jetbrains.com/help/clion/"\>jetbrains.com/help/clion/\</a\>.
//  Also, you can try interactive lessons for CLion by selecting
//  'Help | Learn IDE Features' from the main menu.

2 Answers 2

2

The little light bulb icons you see are a CLion feature, not a C++ feature. There's no way to put them into your source code, nor should you try to do so.

C++ source files are just plain text files. As such, there are no hidden properties or any magic functionality in them. You don't need a sophisticated IDE to write them, a simple text editor is enough.

IDEs provide functionality to make editing source code files more convenient. The Ctrl + / is one example. Comments in C++ are either // line comment or /* block comment */ and you can just type it out - or use the IDE's shortcut to insert a comment.

In a similar way, CLion has a special treatment for comments starting with "TIP" if "onboarding comments" is enabled. These are rendered differently as can be seen in your screenshots.

This is a kind of tooltip intended to make CLion easier to use for new users. Again: this is CLion, not C++. For C++, // TIP is just a comment and will be ignored. You can put a hundred of these comments in your source code and not change the behavior of the resulting program. Don't expect this to work (in different IDEs) and don't rely on it. It won't work for your co-worker using a different editor/IDE.


As a side note, I would suggest to try a different IDE for some time to make sure you learn the language, not the tool. A change in perspective tends to give new insights.

Sign up to request clarification or add additional context in comments.

Comments

0

It's a render bug in CLion and this type of comments are not supported in other IDEs as Friedrich points out. You need to decide if it's worth it or not. They're easy to remove, anyway (just find-replace // TIP with //)

There is a lot you can do with comments like TODO which are fairly supported by most IDEs.

You may als be interested in creating documentation from comments with doxygen.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.