Comparing same types with different names

Konstantin

I've got

typedef void* TA;
typedef void* TB;

I need to compare names of types as different types. There are std::is_same<TA, TB>::value and typeid(TA)==typeid(TB) return true, but I need false.

Ayxan Haqverdili

That is not possible because they are the same type.

If you are trying to use these as opaque handles with strong type-checking, another thing you can do is to forward-declare the classes in a header, and define them in your implementation file:

// ta_tb.hpp

typedef struct ta_impl* TA;
typedef struct tb_impl* TB;

Later:

// ta_tb.cpp

struct ta_impl { /* ... */ };
struct tb_impl { /* ... */ };

This enables type-checking for the handles, but doesn't leak the implementation details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Type for with same field names but different types

Export same function with different names and types

structs with same name and same meber types but different member names

Is there a way to use functions with same names but different return types?

How to serialize object with the same complex prop types, but different names

Comparing boxed values of different types

Comparing different types in Expression Trees

Comparing two classes by its types or class names

Comparing columns to check if they are the same of different

Comparing names in different formats using Python

Comparing names of two files in different directories

Different types of the same object

Data types with same field names

Comparing different types of C++ for-loops

C++ comparing pointers to different types?

comparing two different array types in javascript or jquery

Assertions about comparing different types: redundant and silly?

Comparing different data types with find() in Matlab

Pine Script How to comparing different types

Is it possible to create a type of object from another type of object with the same keys names, but different types of values of them?

Different structs with the same variable names

functions with different names but same arguments

Comparing arrays that have same elements in different order

Comparing of the 2 lists of different objects but with a same fields

Comparing strings in same series (row) but different columns

Comparing same character gives different results

Different names for different objects of same type

Different input types in the same method

XSD different types same name