P
P
Perzh2014-07-10 15:09:45
C++ / C#
Perzh, 2014-07-10 15:09:45

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
   }
};

I cannot understand why this is so. I tried to change the methods in places, but the error remains, and it is on the same line (in the visit method). Please tell me how to fix this. Thanks in advance!
UPD:
If you comment out the use of Device in the visit method, then everything works fine (the project is working, I just finish it):
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

4 answer(s)
D
DancingOnWater, 2014-07-10
@Perzh

Template methods are instantiated the moment they are called. Hence, if the method is not called, then it is not compiled.

J
jcmvbkbc, 2014-07-10
@jcmvbkbc

It seems to me that the correct name of your rubric is "hello, we are looking for telepaths."

M
Misha Krinkin, 2014-07-10
@kmu1990

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.

E
Eugene, 2014-07-10
@EvgenijDv

In your schematic description there is not a word about Device, if there is nothing about it in your code, then the compiler logically swears :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question