🌐
LabEx
labex.io › tutorials › c-how-to-fix-undeclared-identifier-in-c-419180
How to fix undeclared identifier in C | LabEx
In C, an identifier is simply a name that refers to something in your program, such as: ... An identifier is "undeclared" when you try to use it without first telling the compiler what it is.
🌐
Coderanch
coderanch.com › t › 737485 › languages › undeclared-identifier-declared
Use of undeclared identifier that is declared (C / C++ forum at Coderanch)
December 15, 2020 - Hello Guys, I am having some problems with the following piece of code is giving me a compiler error "Use of Undeclared identifier "ParseName" But it is declared in the parse.cpp as followed What am I missing? Thank you, John Matthews · Rancher · Posts: 544 · 17 · posted 5 years ago · 1 · Number of slices to send: Optional 'thank-you' note: Send · Hi Pat Looking at your parse.h file, parseName() is declared as a method of the Parse class.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › error-messages › compiler-errors-1 › compiler-error-c2065
Compiler Error C2065 | Microsoft Learn
August 4, 2025 - // C2065_scope.cpp // compile with: cl /EHsc C2065_scope.cpp #include <iostream> // using namespace std; // Uncomment this line to fix int main() { cout << "Hello" << endl; // C2065 'cout': undeclared identifier // C2065 'endl': undeclared identifier // Or try the following line instead std::cout << "Hello" << std::endl; } Identifiers that are declared inside of class, struct, or enum class types must also be qualified by the name of their enclosing scope when you use them outside of that scope.
🌐
Reddit
reddit.com › r/cs50 › "use of undeclared identifier" error for loops (in c)
r/cs50 on Reddit: "Use of undeclared identifier" error FOR loops (in C)
November 18, 2020 -

Hi CS50 gang!

I'm really enjoying the course, but my brain hurts already at week 2. I've noticed an error when compiling a programme in C when I try to declare a variable inside a FOR loop in C (example below).

I just move my variable declaration to above the FOR loop, but I have two questions about this:

  1. Why does this happen? Is it because the loop tries to declare the variable each time it iterates?

  2. Does it cause problems to declare the variable (int letter_count) above the loop, like I have done in the example below? Or is there a better convention for declaring variables?

 int letter_count = 0;
    //loop to break text string into chars
    for (int i = 0, n = strlen(text); i < n; i++)
    {
        //check if char i is lower or upper and increment letter-count by 1 if true
        if (isupper(text[i]) || islower(text[i]))
        {
            letter_count++;
        }
        
        printf("%c", text[i]);
    }

Thank you!

🌐
Reddit
reddit.com › r/cpp_questions › class : undeclared identifier issue?
r/cpp_questions on Reddit: Class : undeclared identifier issue?
August 9, 2019 -

I am getting this error numerous times in one file which leads me to think that its a simple thing im over looking yet I cannot find a solution to the problem. Any help is greatly appreciated.

I have a post.cpp and post.h (post.h is causing the problem) and it is giving the same error plus others. Please see the list here;

https://ibb.co/VBFc581

I have another class User - all the errors are related to this class for some reason. I am not getting any errors highlighted in the code file in VS only when I run the compiler. I will include the first error here as I dont want to post loads of code to make it hard to solve.

The Post class first error is std::vector<User*> taggesUsers; - you can see it has User in it.

#include "pch.h"

class Post
{
	std::string poster;
	time_t dateTime = DkDateTime::getTimeNow();
	std::string message;
	std::list<std::string> tags;
	std::vector<User*> taggesUsers;

My pch.h

#include <iostream>
#include <string>
#include <vector>
#include <list>


#include "DkDateTime.h"
#include "User.h"
#include "Post.h"

and my user

#pragma once

#include"pch.h"


class User
{
	//Class members
	std::string email;
	std::string password;
	std::string userName;
	time_t lastLogin = DkDateTime::getTimeNow();;

public:

	//Constructor
	User();
	User(std::string email, std::string password, std::string userName);
	~User();

	//Get&Set
	std::string const getEmail() { return email; }
	std::string const getPassword() { return password; }
	std::string const getUserName() { return userName; }
	time_t getLastLogin() { return lastLogin; }

	void setEmail(std::string e) { email = e; }
	void setPassword(std::string p) { password = p; }
	void setUserName(std::string un) { userName = un; }
	void setLastLogin(time_t ll) { lastLogin = ll; }

	//Validation
	bool validateEmail(const std::string email);
	bool validatePassword(const std::string email);
	bool validateUserName(const std::string userName);

	//Overloads
	friend std::ostream& operator<<(std::ostream &out, const User &usr);
	friend std::istream& operator>>(std::istream& in, User& usr);

};

I hope that if you can solve the first error I can get the rest as it seems to be anywhere in the Post.h file I use my User class.

🌐
Reddit
reddit.com › r/learnprogramming › [c++] vector of type 'class' "undeclared identifier"
r/learnprogramming on Reddit: [C++] Vector of type 'class' "undeclared identifier"
March 5, 2020 -

So I've just learned about inheritance in my C++ programming class, and for one of my personal projects I wanted to create a card game. I have an object, 'aDeck', which I want to be a vector of 'aCard' objects.

This is what my .h file for the aDeck class looks like.

#pragma once

#include <vector>
#include "aCard.h"

using namespace std;

class aDeck : public vector<aCard>
{
    public:
    	aDeck(int type);
    	~aDeck();
    	void drawCard(aDeck drawHand);
    	void populateHand(aDeck popHand);
    	void populateDiscard(aDeck gameDeck);
    
    	void outputAll();
    	void outputTop();
};

And this is the .h file for aCard

#pragma once

#include "aDeck.h"
#include <iostream>

using namespace std;

class aCard
{
	public:
		aCard();
		aCard(int color, int number);
		~aCard();
		void displayCard();
	private:
		int cardColor;
		int cardNumber;	
};

This, however, is giving me the error of: "error C2065: 'aCard' : undeclared identifier"

Google says this is because i'm not including the .h file for aCard, which I am. So what would cause something like this?

Top answer
1 of 13
109

They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error:

Missing header

Copyint main() {
    std::cout << "Hello world!" << std::endl;
    return 0;
}

To fix it, we must include the header:

Copy#include <iostream>
int main() {
    std::cout << "Hello world!" << std::endl;
    return 0;
}

If you wrote the header and included it correctly, the header may contain the wrong include guard.

To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.

Misspelled variable

Another common source of beginner's error occur when you misspelled a variable:

Copyint main() {
    int aComplicatedName;
    AComplicatedName = 1;  /* mind the uppercase A */
    return 0;
}

Incorrect scope

For example, this code would give an error, because you need to use std::string:

Copy#include <string>

int main() {
    std::string s1 = "Hello"; // Correct.
    string s2 = "world"; // WRONG - would give error.
}

Use before declaration

Copyvoid f() { g(); }
void g() { }

g has not been declared before its first use. To fix it, either move the definition of g before f:

Copyvoid g() { }
void f() { g(); }

Or add a declaration of g before f:

Copyvoid g(); // declaration
void f() { g(); }
void g() { } // definition

stdafx.h not on top (VS-specific)

This is Visual Studio-specific. In VS, you need to add #include "stdafx.h" before any code. Code before it is ignored by the compiler, so if you have this:

Copy#include <iostream>
#include "stdafx.h"

The #include <iostream> would be ignored. You need to move it below:

Copy#include "stdafx.h"
#include <iostream>

Feel free to edit this answer.

2 of 13
21

Consider a similar situation in conversation. Imagine your friend says to you, "Bob is coming over for dinner," and you have no idea who Bob is. You're going to be confused, right? Your friend should have said, "I have a work colleague called Bob. Bob is coming over for dinner." Now Bob has been declared and you know who your friend is talking about.

The compiler emits an 'undeclared identifier' error when you have attempted to use some identifier (what would be the name of a function, variable, class, etc.) and the compiler has not seen a declaration for it. That is, the compiler has no idea what you are referring to because it hasn't seen it before.

If you get such an error in C or C++, it means that you haven't told the compiler about the thing you are trying to use. Declarations are often found in header files, so it likely means that you haven't included the appropriate header. Of course, it may be that you just haven't remembered to declare the entity at all.

Some compilers give more specific errors depending on the context. For example, attempting to compile X x; where the type X has not been declared with clang will tell you "unknown type name X". This is much more useful because you know it's trying to interpret X as a type. However, if you have int x = y;, where y is not yet declared, it will tell you "use of undeclared identifier y" because there is some ambiguity about what exactly y might represent.

🌐
Reddit
reddit.com › r/learnprogramming › [c] getting a "error: use of undeclared identifier c" when calling function even though it's declared.
r/learnprogramming on Reddit: [C] Getting a "error: use of undeclared identifier c" when calling function even though it's declared.
March 31, 2017 -

Hello, I'm new to programming and while coding my example program I ran into an issue that I've been trying to figure out how to resolve. When print_Menu_Info(); executes and it tries to execute print_Customer_Table(&c); I encounter the error in the title.

sales.c:101:24: error: use of undeclared identifier 'c'

Even though the line is being declared in line 12.

struct customer c = empty_customer;

#include <stdio.h>
#include <stdlib.h>
#include "sales.h"

int main(void)
{
    menu_update();
    return 0;
}

void menu_update(void){
    struct customer c = empty_customer;
	float f = 0.00;
	int i = 0;
	while (1) {
	    cls();
	    print_Menu_Info();
	    switch(get_User_Input()){
	        case 1:
				printf("Customer First Name: ");
				scanf("%s",c.first_Name);
	            break;
	        case 2:
				printf("Customer Last Name: ");
				scanf("%s",c.last_Name);
	            break;
	        case 3:
				printf("Customer Amount: ");
				scanf("%f",&f);
				c.amount = f;
	            break;
	        case 4:
				printf("Customer Card Number: ");
				scanf("%s",c.card_Number);
	            break;        
	        case 5:
				printf("Customer Card Expiration Month: ");
				scanf("%i",&i);
				c.card_Expiration_Month = i;
	            break;
	        case 6:
				printf("Customer Card Expiration Year: ");
				scanf("%i",&i);
				c.card_Expiration_Year = i;
	            break;
	        case 7:
				printf("Sales Person: ");
				scanf("%s",c.sales_Person);
	            break;
            case 8:
                print_Customer_Table(&c);
                break;
            case 9:
                c = empty_customer;
                break;
	        case 10:
	            exit(0);
	        default:
	            printf("Incorrect action ID!\n");
	            break;
	    }    
	}
}

void cls(void){
    printf("\033c");
}

int get_User_Input(){
	int a = 0;
    char line[32];
    printf("Please input an action ID: ");
	if (fgets(line, sizeof(line), stdin) != NULL) {
    	sscanf(line, "%i", &a);
    	cls();
    }
	return a;
}


void print_Customer_Table(struct customer *cp){
    printf(
    "1. Customer First Name: %s\n"
    "2. Customer Last Name: %s\n"
    "3. Customer Amount: $%.2f\n"
    "4. Customer Card Number: %s\n"
    "5. Customer Card Expiration Month: %i\n"
    "6. Customer Card Expiration Year: %i\n"
    "7. Sales Person: %s\n",
    cp->first_Name,
    cp->last_Name,
    cp->amount,
    cp->card_Number,
    cp->card_Expiration_Month,
    cp->card_Expiration_Year,
    cp->sales_Person);
}

void print_Menu_Info(void){
	print_Customer_Table(&c);
	printf(
	"If you would like to update a value type the value you would like to update(1-7)\n"
    "If you would like to send this as a email type 8\n"
    "If you would like to clear all customer data type 9\n"
    "If you would like to exit this program type 10\n");
}                

and sales.h

#define NAME_LEN_MAX 128
#define CARD_NUM_LEN_MAX 16
struct customer {
    char first_Name[NAME_LEN_MAX + 1];
    char last_Name[NAME_LEN_MAX + 1];
    float amount;
    char card_Number[CARD_NUM_LEN_MAX + 1];
    int card_Expiration_Month;
    int card_Expiration_Year;
    char sales_Person[NAME_LEN_MAX + 1];
};
const static struct customer empty_customer = {{""},{""},0.00,{""},0,0,{""}};
void print_Customer_Table(struct customer *cp);
void print_Menu_Info(void);
void cls(void);
int get_User_Input();
void menu_update(void);
Find elsewhere
🌐
Microsoft
social.msdn.microsoft.com › Forums › vstudio › en-US › 21a595db-6098-453f-a203-29ed09eb591e › undeclared-identifier-c2065-but-i-did-declared-it
undeclared identifier c2065 but i did declared it | Microsoft Learn
August 3, 2021 - The compiler operates on only one cpp file at a time. "Undeclared identifier" means the identifier has not been declared during the processing of the current cpp file being compiled.
🌐
Coderanch
coderanch.com › t › 729601 › languages › undeclared-identifier
C++ use of undeclared identifier (C / C++ forum at Coderanch)
April 23, 2020 - Here is my code here is my error list CSE450Program.cpp:22:16: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int weight = 0; ^ CSE450Program.cpp:32:5: error: use of undeclared identifier 'flight'; did you mean 'right'? flight[std::make_pair(start,end)] = wt; ^~~~~~ right /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:957:1: note: 'right' declared here right(ios_base& __str) ^ CSE450Program.cpp:32:11: error: type 'std::__1::ios_base &(std::__1::ios_base &)' does not provide a subscript operator &nbsp; flight[std::make_pair(start,end)] = wt; ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ CSE450Program.cpp:33:5: error: use of undeclared identifier 'weight' weight = weight + wt; ^ CSE450Program.cpp:33:14: error: use of undeclared identifier 'weight' weight = weight + wt; ^ 1 warning and 4 errors generated.
🌐
Ars OpenForum
arstechnica.com › forums › operating systems & software › microsoft os & software colloquium
undeclared identifier problem with C++ class | Ars OpenForum
October 26, 2001 - but thought i already declared them in the .h file here's the errprs i'im getting<BR><BLOCKQUOTE><font size="-1">code:</font><HR><pre> Trianglei.cpp(10) : error C2550: 'Trianlge' : constructor initializer lists are only allowed on constructor definitions<BR>CTrianglei.cpp(11) : error C2065: 'newangle' : undeclared identifier<BR>CTrianglei.cpp(11) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data<BR>CTrianglei.cpp(12) : error C2065: 'setTriangle' : undeclared identifier<BR>CTrianglei.cpp(13) : warning C4508: 'Trianlge' : function should return a value; 'void' retur
🌐
Cplusplus
cplusplus.com › forum › general › 168763
Error "use of undeclared identifier" - C++ Forum
July 3, 2015 - And probably that's why it is showing the error "undeclared identifier" In this case, you should declare "double balance" in your header file so that any other function can use that variable. Hope this helps! Last edited on · sdubs177 (4) Thank you! I just edited my question to include the ...
🌐
Cplusplus
cplusplus.com › forum › general › 91189
Undeclared Identifier, but it is declare - C++ Forum
January 29, 2013 - I tried that but it still says 'Undeclared Identifier!' I even tried putting the object declaration outside of the switch statement, but the error is still there. ... That's goofy. I do believe that the brackets are necessary when declaring variables within a case so you'll need that eventually.
🌐
Quora
quora.com › What-does-undeclared-identifier-mean-in-C++-and-what-should-I-do-to-fix-the-error
What does 'undeclared identifier' mean in C++. and what should I do to fix the error? - Quora
It will tell you what the undeclared identifier is, and you can go figure out why the compiler doesn't know about it. Maybe you forgot to declare it. Maybe it was declared out of scope. Maybe it's a member variable/function and you are not in the same class. Maybe it was a typo in the declaration.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting › c++
'error C2065: "AClass": undeclared identifier' appeared but header file still #included? - C++ - Epic Developer Community Forums
September 6, 2014 - Hi All I’ve got this error- as if I haven’t included the header file for the class and the compiler can’t tell what it is. The code that it’s suddenly having a problem with has been in the project for a while, and has c…
🌐
JustAnswer
justanswer.com › computer-programming › o6dm7-qt-c-fix-use-undeclared-identifier.html
How to Fix 'Use of Undeclared Identifier' in C, C++, and Qt
Verify that the variable name matches the class usage, e.g., QTcpServer *tcpServer = new QTcpServer();. Also, check your project’s .pro file includes the network module (QT += network). Properly declaring and initializing tcpServer resolves the undeclared identifier issue.