using-directives

Restricting `using` directives to the current file

痴心易碎 提交于 2019-12-23 10:14:32
问题 Sorry for this silly question, but is there any way to restrict using directives to the current file so that they don't propagate to the files that #include this file? 回答1: Perhaps wrapping the code to be included inside its own namespace could achieve the behavior you want, since name spaces have scope affect. // FILENAME is the file to be included namespace FILENAME_NS { using namespace std; namespace INNER_NS { [wrapped code] } } using namespace FILENAME_NS::INNER_NS; and in some other

How to prevent ReSharper from shortening namespaces when adding using directives?

你离开我真会死。 提交于 2019-12-21 07:56:08
问题 When I use ReSharper to add a using directive (using Alt+Enter) it removes "unnecessary" parts of the namespace. I prefer using the full namespace which is also the behavior of Visual Studio. Example: namespace MyCompany.MyTool.Data { // This is what ReSharper gives me: using Core; // This is what I want: using MyCompany.MyTool.Core; // ... } Which setting do I have to change in ReSharper 4.5 so it uses the full namespace? 回答1: I don't have ReSharper 4.5 installed at the moment, but in 5.0

What's the purpose of: “using namespace”?

风格不统一 提交于 2019-12-21 03:23:25
问题 There are convincing arguments against using namespace std , so why was it introduced into the language at all? Doesn't using namespace defeat the purpose of namespaces? Why would I ever want to write using namespace ? Is there any problem I am not aware of that is solved elegantly by using namespace , maybe in the lines of the using std::swap idiom or something like that? 回答1: For one thing, this is the way to use operator overloads in a namespace (e.g using namespace std::rel_ops; or using

C++ 'typedef' vs. 'using … = …' [duplicate]

一曲冷凌霜 提交于 2019-12-21 03:12:16
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What are the differences between typedef and using in C++11? The following code compiles and runs. My question is what is the difference between the "typedef" and "using" method for renaming the template specialization? template<typename T> struct myTempl{ T val; }; int main (int, char const *[]) { using templ_i = myTempl<int>; templ_i i; i.val=4; typedef myTempl<float> templ_f; templ_f f; f.val=5.3; return 0; }

Drilldown charts in angular js using google charts directives

僤鯓⒐⒋嵵緔 提交于 2019-12-19 12:09:09
问题 We are new to angularjs v4. We have a requirement of drilldown charts in google charts. We are using ng2-google-charts directives. We are able to find the select event and updated the data. but chart is not reloading. Could any one please help on this. view: index.html <pre> <br/> <google-chart #drillchart [data]='pieChartData' type="BarChart" (chartSelect)='select($event)'> </google-chart> </pre> Component.ts: pieChartData = { chartType: 'BarChart', dataTable: [ ['Country', 'Poulation'], [

Can class members be defined outside the namespace in which they are declared?

余生颓废 提交于 2019-12-19 05:13:19
问题 Sometimes I find code like the following (actually some class-wizards create such code): // C.h namespace NS { class C { void f(); }; } and in the implementation file: // C.cpp #include "C.h" using namespace NS; void C::f() { //... } All the compilers I tried accept that kind of code (gcc, clang, msvc, compileonline.com). What makes me feel uncomfortable is the using namespace NS; . From my point of view C::f() lives in the global namespace in an environment that has unqualified access to

Namespace references in C# vs. VB.Net

99封情书 提交于 2019-12-18 21:53:54
问题 In VB.Net you can do something like the following without any issues... just ignore the fact that this is a pretty useless class :-) Imports System Public Class Class1 Public Shared Function ArrayToList(ByVal _array() As String) As Collections.Generic.List(Of String) Return New Collections.Generic.List(Of String)(_array) End Function End Class However if you do the same thing in C#... using System; public class Class1 { public static Collections.Generic.List ArrayToList(string[] _array) {

Duplicated using directives in multiple files

ε祈祈猫儿з 提交于 2019-12-18 08:27:13
问题 I have got 5 C# files that have 20 using directives in common. I want to get rid of this code duplication, especially because these 20 using directives belong logically together. In C or C++ I would have created an extra header file containing these 20 include files. This extra header file acts as a layer then to include the 20 other files in one go. Unfortunately I don't know how to do this in C#. Any suggestions? 回答1: You can't do this in C# since C# does not have a preprocessor, and the C#

Why is std:: used by experienced coders rather than using namespace std;? [duplicate]

放肆的年华 提交于 2019-12-18 05:45:30
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why is 'using namespace std;' considered a bad practice in C++? The other day when I asked a question someone replied saying if someone asks a question, show them the right way to do it instead of using namespace std; which I thought was a bit weird, as using namespace std; is way easier, But I guess I'm failing right now as I am a 'beginner' coder and you guys know better. So I guess my question is: Why std::

What requires me to declare “using namespace std;”?

左心房为你撑大大i 提交于 2019-12-18 04:37:06
问题 This question may be a duplicate, but I can't find a good answer. Short and simple, what requires me to declare using namespace std; in C++ programs? 回答1: Since the C++ standard has been accepted, practically all of the standard library is inside the std namespace. So if you don't want to qualify all standard library calls with std:: , you need to add the using directive. However, using namespace std; is considered a bad practice because you are practically importing the whole standard