# Solved: C++ 'undeclared' error



## alex_holker (Sep 28, 2003)

Hey guys, I'm getting an error here, and I was hoping someone could tell me what I'm doing wrong. I'm getting two compile errors, saying that pracErrorLog and studentErrorLog are undeclared in the printErrorLog function.

To be precise, it says: "pracErrorLog undeclared (first use this function)"

I have used these two variables elsewhere in the class without problem (removed for brevity). Is it because that function is trying to read from the strings, rather than only making additions to the string?


```
#include <iostream>
#include <string>

using namespace std;

class ErrorLogging
{
    string pracErrorLog;
    string studentErrorLog;
    
    public:
        ErrorLogging();

...
        void printErrorLog();
};

ErrorLogging::ErrorLogging()
{
    pracErrorLog = "\n Practical Error Log\n ===================\n";
    studentErrorLog = "\n Student Error Log\n =================\n";
}

...    

void printErrorLog()
{
    cout << pracErrorLog;
    cout << studentErrorLog;
}
```
Alex


----------



## Regicide (Aug 8, 2003)

What it seems it happening is that even though you declared printErrorLog in the class, you are not referencing it as a class member. What I mean is that you have to put ErrorLogging:: before you code any function of a class outside of the class declaration. The template for doing do is like this: returntype ClassName::ClassFunction(). So, printErrorLog should look like this:

```
void ErrorLogging::printErrorLog()
{
    cout << pracErrorLog;
    cout << studentErrorLog;
}
```


----------



## alex_holker (Sep 28, 2003)

Thanks Regicide. I forgot to add that to the last function, and didn't notice my mistake. Unfortunately, fixing that error revealed other problems in the other class. 

[edit] There were only a few, easily identified errors in the other class, so I've got this version working now.

Alex


----------

