---
title: "What is the difference between “typedef” and “]using” in C++?"  
description: "What is the difference between “typedef” and “]using” in C++?"  
author: "Utpal Vishwas"  
published: 2023-07-07  
updated: 2023-07-10  
canonical: https://www.mindstick.com/forum/158996/what-is-the-difference-between-typedef-and-using-in-c-plus-plus  
category: "visual c++"  
tags: ["c++", "programming language"]  
reading_time: 2 minutes  

---

# What is the difference between “typedef” and “]using” in C++?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between “typedef” and “]using” in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)?

## Replies

### Reply by Aryan Kumar

The `typedef` and `using` keywords in C++ are both used to create aliases for data types. However, there are some key differences between the two keywords.

- `typedef` **defines a new type, while** `using` **creates an alias for an existing type.** This means that you can use a `typedef` to declare variables, while you can only use a `using` to refer to a variable that has already been declared using a `typedef` or a `using`.
- `typedef` **can be used to create aliases for any type, while** `using` **can only be used to create aliases for user-defined types.** This means that you cannot use a `using` to create an alias for a built-in type, such as `int` or `float`.
- `typedef` **declarations are hoisted, while** `using` **declarations are not.** This means that the `typedef` declarations are evaluated at the top of the scope in which they are declared, while the `using` declarations are evaluated at the point where they are encountered.

In general, you should use `typedef` if you want to define a new type that you will be using frequently. You should use `using` if you want to refer to an existing type without having to write out the full name of the type every time you want to use it.

Here are some examples of how to use `typedef` and `using`:

C++

```plaintext
// Define a new type called `Point` that is a struct
typedef struct Point {
  int x;
  int y;
} Point;

// Declare a variable of type `Point`
Point point;

// Create an alias for the `Point` type called `MyPoint`
using MyPoint = Point;

// Declare a variable of type `MyPoint`
MyPoint my_point;
```

In both cases, the variable `point` and the variable `my_point` will be of type `Point`. However, the first code defines a new type called `Point`, while the second code simply creates an alias for the existing type `struct Point`.

The `using` declaration in the second code is not hoisted, which means that the `MyPoint` alias is not evaluated until the point where it is encountered. This can lead to some unexpected behavior, so it is generally recommended to use `typedef` instead of `using` if you want to define a new type.


---

Original Source: https://www.mindstick.com/forum/158996/what-is-the-difference-between-typedef-and-using-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
