using-directives

Scoped using-directive within a struct/class declaration? [duplicate]

萝らか妹 提交于 2019-11-27 12:24:23
This question already has an answer here: Why “using namespace X;” is not allowed inside class/struct level? 3 answers I find that my C++ header files are quite hard to read (and really tedious to type) with all the fully-qualified types (which goes as deep as 4 nested namespaces). This is the question (all the answers give messy alternatives to implementing it, but that's not the question): Is there a strong reason against introducing scoped using-directive in structs and classes in the C++ language (while it's permissible to have scoped using-declaration in functions)? e.g. class Foo :

Ordering of using namespace std; and includes?

主宰稳场 提交于 2019-11-27 09:28:12
I recently saw this code being used in a source file in a C++ project: using namespace std; #include <iostream> Ignoring all issues of whether it's a good idea to have using namespace std at all, is the above code even legal? There is no code in the file before these two lines. I would have thought that this wouldn't compile, since namespace std hasn't been declared in scope until the #include <iostream> directive includes it into the file, but using the build system for the project this was compiling just fine. If someone has a link to a relevant part of the spec, that would be most

Default using directives in new C# files

僤鯓⒐⒋嵵緔 提交于 2019-11-27 05:49:04
问题 Why does Visual Studio 2008 automatically insert the following using directives into each new C# file I create? using System; using System.Collections.Generic; using System.Text; What's so special about these namespaces? Are these the most frequently used ones? 回答1: Yes, they're frequently used, that's all, so MS put them in the Visual Studio templates. Personally I use "sort and remove unused usings" pretty frequently, so they often go away. If you want to remove them, you can amend the "new

Visual Studio or Resharper functionality for placement of using directives

好久不见. 提交于 2019-11-27 03:36:45
I like to put my using directives inside the current namespace, and not outside as VS and Resharper per default puts them. Does anyone know of a macro/standard functionality that sorts/removes unused using directives and puts them inside the current namespace? marklam UPDATE - ReSharper 2016.1 : This option is now moved to Code Editing → C# → Code Style → Add 'using' directive to the deepest scope Have you tried the ReSharper option: Languages → C# → Formatting Style → Namespace Imports → Add using directive to the deepest scope I'm not sure whether R#'s code cleanup will reorder the existing

Ordering of using namespace std; and includes?

时光怂恿深爱的人放手 提交于 2019-11-26 17:51:13
问题 I recently saw this code being used in a source file in a C++ project: using namespace std; #include <iostream> Ignoring all issues of whether it's a good idea to have using namespace std at all, is the above code even legal? There is no code in the file before these two lines. I would have thought that this wouldn't compile, since namespace std hasn't been declared in scope until the #include <iostream> directive includes it into the file, but using the build system for the project this was

Visual Studio or Resharper functionality for placement of using directives

雨燕双飞 提交于 2019-11-26 15:39:10
问题 I like to put my using directives inside the current namespace, and not outside as VS and Resharper per default puts them. Does anyone know of a macro/standard functionality that sorts/removes unused using directives and puts them inside the current namespace? 回答1: UPDATE - ReSharper 2016.1 : This option is now moved to Code Editing → C# → Code Style → Add 'using' directive to the deepest scope Have you tried the ReSharper option: Languages → C# → Formatting Style → Namespace Imports → Add

The type or namespace name could not be found [duplicate]

余生颓废 提交于 2019-11-25 22:43:14
问题 This question already has an answer here: Getting “type or namespace name could not be found” but everything seems ok? 33 answers I have a C# solution with several projects in Visual Studio 2010 . One is a test project (I\'ll call it \" PrjTest \"), the other is a Windows Forms Application project (I\'ll call it \" PrjForm \"). There is also a third project referenced by PrjForm, which it is able to reference and use successfully. PrjForm references PrjTest , and PrjForm has a class with a

Why is “using namespace std;” considered bad practice?

99封情书 提交于 2019-11-25 22:09:18
问题 I\'ve been told by others that writing using namespace std; in code is wrong, and that I should use std::cout and std::cin directly instead. Why is using namespace std; considered a bad practice? Is it inefficient or does it risk declaring ambiguous variables (variables that share the same name as a function in std namespace)? Does it impact performance? 回答1: This is not related to performance at all. But consider this: you are using two libraries called Foo and Bar: using namespace foo;