0

Normally I program in C# but have been forced to do some work in C++. It seems that the integration with Visual Studio (2008) is really poor compared to C# but I was wondering if there are any good tools, plugins or configurations that can improve the situation.

Another post pointed out the program Visual Assist X, which at least helps with some things such as refactoring (though it is a bit expensive for me). My major problem is, though, that the compile errors give little clue about what is wrong and I spend most of my time figuring out what I did wrong. It just feels like it is possibly to statically check for a lot more errors than VS does out of the box. And why doesn't it provide the blue underlines as with C#, that shouldn't be too hard?!

I realize that half the problem is just the fact that I am new to C++ but I really feel that it can be unreasonably hard to get a program to compile. Are there any tools of this sort out there or are my demands too high?

4

3 回答 3

7

我认为有两种可能性:1)要么你正在尝试 C++ 的东西,这超出了你的知识(因此,你不知道你做错了什么以及如何解释错误消息),2)你太高了期望。

提示:许多后续错误是由第一个错误引起的。当我得到大量错误列表时,我通常只纠正第一个错误并重新编译。您会惊讶于缺少分隔符或类型声明会产生多少垃圾(就错误消息而言):)

在编译之前很难对 C++ 程序进行语法分析,主要有两个原因:1) C++ 语法是上下文相关的,2) 模板是图灵完备的(将它们视为具有奇怪语法的函数式编程语言)。

于 2008-10-02T17:08:03.140 回答
4

我的建议:

  • 如果您想要 C# 中的更多功能,请获取VisualAssist X并了解如何使用它。它不是免费的,但可以为您节省大量时间。
  • 将您的警告级别设置为高(这最初会产生更多的编译错误,但当您修复它们时,您会对常见错误有所了解)。
  • 将警告设置为错误,这样您就不会养成忽略警告的习惯。
  • 要了解编译错误,请使用 Google(不要在帮助系统上浪费时间)搜索警告错误编号(它们看起来像这样:C4127)。
  • 避免使用模板,直到使用上述方法编译代码且没有错误。如果您不太了解模板,请学习!买一些书,做一些教程,然后从小事做起。众所周知,模板编译错误很难弄清楚。Visual C++ 2008 的错误消息比以前的版本好得多,但仍然很难。
  • 如果您开始认真地制作模板,请准备一个宽屏显示器(甚至两个),以便更轻松地阅读详细错误。
于 2008-10-02T18:44:29.150 回答
3

视觉辅助 +1,也许不是现在——但当你把爱好变成职业时,你会需要它。

根据我的经验,诊断已经比 VC6 好得多,但是作为学习 IDE 的一部分,您需要“了解”它们的真正含义。

由于构建模式和极其复杂的语言,C++ 的静态检查比 C# 复杂得多。PC-Lint(最好与Visual Lint一起将其集成到 IDE 中)是规范的静态分析。不过也不便宜。。。

C++ 标准有时读起来像圣经,但没有受过训练的传教士来解释它。一位出色的解释器是 Marshal Cline 及其C++ FAQ。请注意,在线常见问题解答虽然内容广泛,但涵盖的内容远少于本书

帮助我理解复杂错误消息的主要方法是尝试在较小的环境中重现问题 - 但是当时没有互联网......

于 2008-10-26T21:12:43.017 回答