namespaces

Using-directive class static functions?

和自甴很熟 提交于 2019-12-23 16:53:50
问题 I am using an API that has a lot of functions in a class named TCODConsole as static functions. Now I thought that it was in a namespace, so I wrote: using namespace TCODConsole; . Then I found out that TCODConsole ain't a namespace, but a class. Is there a way to import those functions in a similar way as you would use using namespace ? 回答1: Though I may misunderstand the question, if shortening the qualification is the objective, does typedef ing like the following meet the purpose? struct

How to overload the operator<< from within a namespace

扶醉桌前 提交于 2019-12-23 16:48:27
问题 This is the smallest contained example I can think of. First the header of the class. This class should simply print the one double it contains whenever the << operator is used. #pragma once #ifndef EURO_H #define EURO_H #include <ostream> namespace EU { class Euro final { public: explicit Euro(double value); virtual ~Euro() = default; double getValue() const; friend std::ostream& operator<<(std::ostream &os, const Euro &euro); private: double m_value; }; } #endif // EURO_H Now the .cpp

Cannot find namespace “ServiceModel” with Unity

假如想象 提交于 2019-12-23 16:44:54
问题 I would like to use a WCF Service (via Named Pipe) in my Unity application. Thus, I include the following two Namespaces: using System.ServiceModel; using System.ServiceModel.Channels; After I run my project in Unity, this leads to the following two errors: Assets/Scripts/program.cs(4,14): error CS0234: The type or namespace name ServiceModel' does not exist in the namespaceSystem'. Are you missing an assembly reference? Assets/Scripts/program.cs(5,14): error CS0234: The type or namespace

C++: What's happen when I use “using namespace xyz” before #include<headerxy> [duplicate]

只愿长相守 提交于 2019-12-23 16:26:48
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Ordering of using namespace std; and includes? I heard that it is strongly prohibited to use "using namespace xy" before "#include ". E.g. #include <iostream> using namespace std; int main() { ... } What's the technical reason for that? I tried following and it worked without any problems: using namespace std; #include <iostream> int main() { .... } 回答1: No, it is not strongly prohibited (otherwise it would be a

Special characters in a Namespace

牧云@^-^@ 提交于 2019-12-23 16:11:33
问题 I am considering using a character with a diacritical mark (e.g., ō) in a namespace for a custom framework. This idea has come up as a way to distinguish a product, but I want to to be sure this isn't a bad idea, and if there is anything about it that will come back to bite me later. I have not seen other examples of namespaces that use special characters in my searching, nor any similar discussion on this topic, which gives me pause in continuing down this path. I was initially considering

Dll reference of one project into another project

时间秒杀一切 提交于 2019-12-23 15:59:20
问题 I have 2 projects, one built in VB.NET and another in C#.NET. I want to use certain functionality of VB.NET into C#.NET and hence I have added the dll file of VB.NET solution into C#.NET as a reference by browsing the dll from my system. Say dll name for VB.NET is myData.dll In my C#.NET project I am trying to declare it as a namespace i.e. "using myData;" and its giving me an error of "Type or namespace name could not be found" Am I missing something?? 回答1: A clue about how your VB.NET

In PHP, how can I wrap procedural code in a class?

女生的网名这么多〃 提交于 2019-12-23 12:57:16
问题 I have a large chunk of legacy php code that I need to interface with that looks like this: //legacy.php function foo() { } function bar() { } I want to be able to wrap these legacy functions in a class or somehow require_once without polluting that global namespace or altering the original file. 回答1: You can use a namespace or static methods in a class: // original file: foo.php class Foo { public static function foo() { } public static function bar() { } } // new file: require 'foo.php';

byte and ambiguous symbol due to using declarations?

佐手、 提交于 2019-12-23 12:25:50
问题 We are a C++ library . For years we had typedef unsigned char byte; in the global namespace. User programs and other libraries provided compatible definitions of byte , so there were no problems. C++17 added std::byte and changed semantics of a byte. Now we need to be more hygienic by avoid global namespace pollution; and we need to insulate ourselves from std::byte . Our change is to move our byte into our namespace. We are witnessing an unexpected failure as we test the impact of changes.

How to properly use namespaces to avoid name collision?

删除回忆录丶 提交于 2019-12-23 12:19:29
问题 I'm a bit confused concerning proper usage of C++ namespaces. It is clear for me how they can help to avoid conflicts (name collision), but it is not clear anymore when it comes to the using keyword. I mean, suppose I have a part of my code that I put into a namespace, and create a class, say namespace my { class vector { ... }; } Of course, when I use it, I wouldn't like to type my::vector all the time, so I'd like using namespace my . However, I could eventually need something from the std

Override used classes in parent class

a 夏天 提交于 2019-12-23 12:16:45
问题 Suppose there is a class NiceClass using some other class LesserClass in a place I can't edit # NiceClass.py class LesserClass: ... # stuff ... class NiceClass: ... # Lots of use of lesser class in here... ... Now I want to use my own class MyLesserClass instead of LesserClass everywhere in an inherited version of NiceClass # MyNiceClass.py from NiceClass import NiceClass from NiceClass import LesserClass as oldLesserClass class LesserClass(oldLesserClass): ... # Some extra stuff ... class