Answer the question
In order to leave comments, you need to log in
Why does the compiler throw error C2065 (daily column "Magic of C++")?
Hello. I am new to C++. I'm tinkering with someone else's project at work. The file has two methods. One of them uses a class. I want to use this class in another method, to which the compiler throws error C2065: undeclared identifier. Here is a schematic description of the situation:
temlate<class Base>
class CLASS
{
void visit()
{
// bla bla bla
Device d; // 'Device' : undeclared identifier
//bla bla bla
}
void Draw()
{
// bla bla bla
Device d; // It's OK
//bla bla bla
}
};
class CLASS
{
void visit()
{
// bla bla bla
// Device d; // now it's OK
//bla bla bla
}
void Draw()
{
// bla bla bla
Device d; // It's OK
//bla bla bla
}
};
Answer the question
In order to leave comments, you need to log in
Template methods are instantiated the moment they are called. Hence, if the method is not called, then it is not compiled.
It seems to me that the correct name of your rubric is "hello, we are looking for telepaths."
Possible options:
1. you described yourself when you wrote Device;
2. you forgot to include/specify the namespace (using namespace ...;);
3. you forgot the semicolon line (or several lines) above;
4. another reason, about which we can only guess, because of your "schematic" presentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question