`X' Is Not a Class or Template Error

Hi, LeafyCircuits here!

Comp Specs
OS: 2002 Windows XP Service Pack 3, Media Center Edition
Compiler: GNU gcc with 2011 C++
IDE: Dev C++ with ISO and STL

Note: Code shown below is a very cut portion of the entire file to focus on the problem and to save you time. Assume that I already know the rest of the code works, for I have tested it already. If you would still like to see the entire file, let me know.

After about 10 months of programming experience, I've started to develop several functions that I use quite often. I've decided to organize all of these functions in a single class called AS_C, sort of like a template. This is my first time trying to implement the class in a project, and I'm having some issues.

In brief: I've made a Caesar Ciphering program, and I'm working on the interface; every other part of the program I've got working. The program is split into 5 files: 3 sources and 2 headers.

Here is the source file that causes the error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <conio.h>
#include "_functions.h"
#include "_classes.h"

using namespace std;
const char arrow=16;

int openOptions(Cipher *ptr_crypt)
{
     char ch;
     AS_C sys;
     
           switch (ch)
           {
                  case '1': //skip this case, one line of it referenced later
                       {
                           string shiftstr;
                           int charcount=0;
                           
                           cout << "\nEnter a number (1-51) for alphabet shift in Key generation,\n";
                           cout << "then press enter. To go back, input 0. Default value is 3.\n\n";
                           ch=getch();
                           
                           while (ch!='\r')
                           {
                                 if (ch=='\b' && charcount>0)
                                 {
                                              shiftstr.erase(0, 1);
                                              charcount--;
                                              cout << "\b \b";
                                 }
                                 
                                 else if (ch>='0' && ch<='9')
                                 {
                                      if (charcount<2)
                                      {
                                                      shiftstr+=ch;
                                                      charcount++;
                                                      cout << ch;
                                      }
                                      
                                      else {}
                                 }
                                 ch=getch();
                           }
                           
                           int shiftnum=sys.strAsInt(shiftstr);
                           if (shiftnum>0 && shiftnum<=51)
                           {
                                          (*ptr_crypt).modShift(shiftnum);
                                          cout << "\n\n\nChange saved.\n\n\n\n";
                                          system("pause");
                           }
                           else if (shiftnum>51)
                           {
                                cout << "\n\n\nNumber too large!\n\n\n\n";
                                system("pause");
                           }
                           
                           else if (!shiftnum==0)
                           {
                                system("cls");
                                cout << "WHAT HAVE YOU DONE?!?!?!\n\n";
                                system("pause");
                           }
                           
                           system("cls");
                           break;
                       }
                  
                  case '2':
                       sys.readFile("Help.txt", sys::no_ret);     //Problem line
                       sys._getch();
                       cout << "\n\n\n\n\n";
                       system("pause");
                       system("cls");
           }
     
}


and the main.cpp that uses it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <conio.h>
#include "_functions.h"
#include "_classes.h"

const char arrow=16;

using namespace std;

main()
{
      AS_C sys;
      Cipher *crypt=new Cipher;
      while (1)
      {
            switch (ch)
            {
                   case '3':
                        openOptions(crypt);
                        break;
            }
      }
}


When I try to compile, it gives me this error in the previous source file:
Line 77: `sys' is not a class or namespace


Here's the header file that defines this AS_C class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class AS_C          //AllStream_Custom. Must include <iostream>, <fstream>, <sstream>, <conio.h>
{
      public:
             enum cmd {ret, no_ret, get_Enter, disp, nodisp};    //error removed until use is needed

             string readFile(string filename, cmd command)
             {
                    ifstream infile(filename.c_str());
                    string line, result;
                    
                    if (!infile.good()) return "";
                    else
                    {
                        switch(command)
                        {
                                       case disp:
                                            while (infile.good())
                                            {
                                                  getline(infile, line);
                                                  result+=(line+"\n");
                                                  cout << line << endl;
                                            }
                                            break;
                                       
                                       case nodisp:
                                            while (infile.good())
                                            {
                                                  getline(infile, line);
                                                  result+=(line+"\n");
                                            }
                                            break;
                                       
                                       case no_ret:
                                            while (infile.good())
                                            {
                                                  getline(infile, line);
                                                  cout << line << endl;
                                            }
                                            return "";
                                       
                                       default:
                                               break;
                        }
                    }
                    
                    infile.close();
                    
                    return result;
             }
};


For some reason, even though this line compiled:
int shiftnum=sys.strAsInt(shiftstr);
That problem line didn't, and even the line after that compiles as well (I think). I made sure that there was an instance of the AS_C class in the function, and that the header file was included in the source so the compiler knows where to find the definition of AS_C. The file I'm trying exists and isn't corrupted, so it isn't that. Perhaps I'm missing one small thing, but I've looked at this several times. But hey, we all make mistakes :)




I'm new to the forums, so constructive criticism on anything is greatly appreciated.
I'm a noob, so this is probably a stupid question, but did you try AS_C::no_ret instead of sys::no_ret?
closed account (Dy7SLyTq)
edit: sorry fg109 misread what you wrote yes he is write
Last edited on
no. sys is a variable not a scope


Well, duh. That's what the compiler told the OP.

AS_C::no_ret is the correct way to get at the constant.
Oh yeah. Thanks guys for replying!
closed account (Dy7SLyTq)
@cire i misread fg109s post wrong and did that to "correct him". when i saw my mistake i edited it
Topic archived. No new replies allowed.