Type conversion to another class with namespace?

surfcode

Normally, one could write a conversion operator to convert to another class like

struct A {};

struct B
{
    operator A()
    {
        return A();
    } 
};

Now, what if A struct has a namespace different than B:

namespace mars {
struct A {};
}

namespace jupiter {
struct B
{
    operator A()  //??
    {
        return A();
    } 
};
}

What should the operator A() statement become?

Marco A.

You can simply fully qualify the names

namespace mars {
  struct A {};
}

namespace jupiter {
  struct B
  {
    operator mars::A()
    {
      return mars::A();
    } 
  };
}

As a suggestion: try not to do something like

using namespace mars;

in the global scope: that would pollute it and render things more complex when the application grows (e.g. name clashing). Especially for the std namespace, it is often more desirable to fully qualify names to avoid this phenomenon.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Data Conversion from one class type to another class type

From Dev

'Class' is a namespace but is used like a 'type'

From Dev

Class cannot find another class in the same namespace

From Dev

Access form label from another class/namespace

From Dev

Override object creation with same class in another namespace

From Dev

Override object creation with same class in another namespace

From Dev

Import class from another namespace dynamically

From Dev

Dynamic type conversion using Type class

From Dev

The type or namespace name does not exists? (static class)

From Dev

C++ class in namespace does not name type

From Dev

Error trying to build a class : type or namespace name

From Dev

Php use a class in the constructor of another class and require it with namespace

From Dev

Php use a class in the constructor of another class and require it with namespace

From Dev

C# List inside class and namespace, accessing it from another class

From Dev

Ruby type conversion arbitrary by needed class

From Dev

Operator Overload for Template Class Auto Type Conversion

From Dev

Ruby type conversion arbitrary by needed class

From Dev

IEnumerable Class Collection type conversion from List

From Dev

Another "conversion from type DBNull to type Date not valid" issue

From Dev

C# Type or namespace name could not be found in another project

From Dev

How to access enum present as a template class member in another namespace?

From Dev

Convert the child object pointer to the base class(from another namespace) pointer

From Dev

Using an interface class as member type in another class

From Dev

How to declare a class based on type of another class

From Dev

Attempted to load class "Sm_Image_HandlerController" from namespace Did you forget a "use" statement for another namespace?

From Dev

Symfony 2 Attempted to load class " " from namespace " " Did you forget a "use" statement for another namespace?

From Dev

implicit conversion of vector from one type to another c++

From Dev

Type conversion to a structure which has another structure ptr in it

From Dev

Type conversion to a structure which has another structure ptr in it

Related Related

  1. 1

    Data Conversion from one class type to another class type

  2. 2

    'Class' is a namespace but is used like a 'type'

  3. 3

    Class cannot find another class in the same namespace

  4. 4

    Access form label from another class/namespace

  5. 5

    Override object creation with same class in another namespace

  6. 6

    Override object creation with same class in another namespace

  7. 7

    Import class from another namespace dynamically

  8. 8

    Dynamic type conversion using Type class

  9. 9

    The type or namespace name does not exists? (static class)

  10. 10

    C++ class in namespace does not name type

  11. 11

    Error trying to build a class : type or namespace name

  12. 12

    Php use a class in the constructor of another class and require it with namespace

  13. 13

    Php use a class in the constructor of another class and require it with namespace

  14. 14

    C# List inside class and namespace, accessing it from another class

  15. 15

    Ruby type conversion arbitrary by needed class

  16. 16

    Operator Overload for Template Class Auto Type Conversion

  17. 17

    Ruby type conversion arbitrary by needed class

  18. 18

    IEnumerable Class Collection type conversion from List

  19. 19

    Another "conversion from type DBNull to type Date not valid" issue

  20. 20

    C# Type or namespace name could not be found in another project

  21. 21

    How to access enum present as a template class member in another namespace?

  22. 22

    Convert the child object pointer to the base class(from another namespace) pointer

  23. 23

    Using an interface class as member type in another class

  24. 24

    How to declare a class based on type of another class

  25. 25

    Attempted to load class "Sm_Image_HandlerController" from namespace Did you forget a "use" statement for another namespace?

  26. 26

    Symfony 2 Attempted to load class " " from namespace " " Did you forget a "use" statement for another namespace?

  27. 27

    implicit conversion of vector from one type to another c++

  28. 28

    Type conversion to a structure which has another structure ptr in it

  29. 29

    Type conversion to a structure which has another structure ptr in it

HotTag

Archive