---
title: "How can I resolve \"undeclared function\" errors in C++?"  
description: "How can I resolve \"undeclared function\" errors in C++?"  
author: "Revati S Misra"  
published: 2023-09-14  
updated: 2023-09-25  
canonical: https://www.mindstick.com/forum/159894/how-can-i-resolve-undeclared-function-errors-in-c-plus-plus  
category: "visual c++"  
tags: ["exception handling", "error", "c++"]  
reading_time: 3 minutes  

---

# How can I resolve "undeclared function" errors in C++?

How can I [resolve](https://www.mindstick.com/forum/159427/windows-app-dll-not-found-resolve-library-issue) "undeclared [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)" [errors](https://answers.mindstick.com/qa/116170/fresh-fir-against-gandhis-in-national-herald-case-cover-up-for-ed-s-own-errors) in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)?

## Replies

### Reply by Aryan Kumar

In C++, an "undeclared function" error typically occurs when you're trying to use a function that the compiler hasn't seen a declaration for before you call it. This can happen for several reasons, and resolving it involves ensuring that the function is properly declared and defined in your code. Here are steps to resolve "undeclared function" errors:

- **Check for Typos**: Ensure that there are no typos in the function name. C++ is case-sensitive, so "**myFunction**" and "**myfunction**" are considered different functions.
- **Include Header Files**: If the function you're trying to use is part of a library or another source file, make sure you include the necessary header files at the top of your source file using **#include** directives. For example:

```plaintext
#include "mylibrary.h"
```

- **Function Declaration**: Ensure that the function you're using has been declared before you call it. A function declaration typically appears before the point where it's called in the code. Function declarations include the function name, return type, and parameter list (if any).
- **Function Definition**: If you've only declared the function but haven't provided a definition (implementation) for it, you need to define the function in your code. The definition includes the function body.
- **Namespace**: If the function is part of a namespace, you need to specify the namespace before the function name when calling it. For example:

```plaintext
mynamespace::myFunction();
```

- **Check Scope**: Ensure that the function is in scope. If the function is defined in a class or within another function, you need to make sure you're calling it from the correct scope.
- **Check for Circular Dependencies**: Circular dependencies can lead to undeclared function errors. Make sure your dependencies are properly managed.
- **Compiler Settings**: Ensure that your compiler settings and project configurations are correct. Some build systems may require specific settings or flags to locate and link functions from external libraries.
- **Header Guards**: If you're dealing with header files, ensure that you have proper header guards to prevent multiple inclusions of the same header. Header guards are typically used to prevent redefinition errors and ensure that declarations are included only once.

Here's a simple example of a function declaration and definition in C++:

```plaintext
// Declaration (usually placed in a header file)
int add(int a, int b);

// Definition (usually placed in a source file)
int add(int a, int b) {
    return a + b;
}
```

If you provide more context or specific code that's causing the "**undeclared function**" error, I can provide more targeted assistance.


---

Original Source: https://www.mindstick.com/forum/159894/how-can-i-resolve-undeclared-function-errors-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
