Error expected unqualified id before public

Не компилируется проект. Ошибка: expected unqualified-id before 'public' C++ Решение и ответ на вопрос 2144341

vyacheslav49

0 / 0 / 0

Регистрация: 27.11.2017

Сообщений: 6

1

27.11.2017, 13:10. Показов 3996. Ответов 9

Метки нет (Все метки)


Добрый день коллеги!
У меня есть вопрос: Не компилируется код программы, компилятор выдает следующее сообщение:
[Error] expected unqualified-id before ‘public’

Исходный код программы:

C++
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Test.c    of read file//
 
//#include <iostream>
#include <stdio.h>
#include <string.h>
#include <fstream>
//#include <graphics.h>
#include <dos.h>
//#include "A0_lib_k.c"
using namespace std;
//class A
 
//public:
void Read_serv (void);
int Read_kadr_04 (void);
void Read_sect4 (char,int);
void Print_serv (int);
FILE *fin, *fout;
int kan, set, buf1[18][128], buf2[10][145];
char nam [16], name[] = "test1.txt";
 
int main()
{   int i,len,n=0; 
     
//    char name[16] = "test1.txt";
    printf ("Input filenamme: ");
    scanf ("%s", name);
      
    fin = fopen (name, "rb"); // 
    if (fin != NULL)  printf ("n file '%s' is read", name);       
      else  printf (" No read!n"); //getche();  
// ------
    do
  {
    Read_serv();
    
//  fscanf(fin, "n");
 
    Print_serv (n);
    
    set= Read_kadr_04 ();
    
  } while (set);
//
  return 1; // End
}
 
// ===========================================
  public //private:
  void Read_kadr_04 (void)  // read bank0, 1-4 lines;
// -------------------------------------------
{ int k,i,set,kan;
 
    fscanf (fin, "nback : high sensitivity :");
     Read_sect4 (0, 69);
    fscanf (fin, "nback : low sensitivity :" );
     Read_sect4 (1, 69);
    fscanf (fin, "nback1 : high sensitivity :");
     Read_sect4 ( 2, 72); // buff 2
    
    fscanf(fin,"nfront : high sensitivity :");
     Read_sect4 ( 3, 69);
    fscanf(fin, "nfront : low sensitivity :");
     Read_sect4 (  4, 69);
    fscanf(fin, "nfront1 : high sensitivity :");
     Read_sect4 (5, 72);
 
    fscanf(fin, "nleft : high sensitivity :");
     Read_sect4 ( 6, 50);
    fscanf(fin,"left : low sensitivity :");
     Read_sect4 (7, 50);
    fscanf(fin,"nleft1 : high sensitivity :");
     Read_sect4 ( 8, 48);
    fscanf(fin,"nmiddle1 : high sensitivity :");
     Read_sect4 (9,48);
 
    fscanf(fin,"nright : high sensitivity :");
     Read_sect4 ( 10,50);
    fscanf(fin,"nright : low sensitivity :");
     Read_sect4 (11,50);    // line1
    fscanf(fin,"right1 : high sensitivity :");
     Read_sect4 (12,48);    // line1
  // -------
    fscanf(fin,"scinti : high sensitivity :");
    Read_sect4 ( 13,40);
    fscanf(fin,"scinti : midi sensitivity :");
    Read_sect4 ( 14,40);
    set= fscanf (fin, "n#");
 
// --- Gamma, line-1 (right, left)
     for (k=0; k<50; k++)
    { buf2[0][k] = buf1[10][k];   buf2[0][k+50] = buf1[6][k];   // high
        buf2[1][k] = buf1[11][k];   buf2[1][k+50] = buf1[7][k]; // low
    }
// --- Gamma, line-2 (front, back)
     for (k=0; k<69; k++)
    { buf2[2][k] = buf1[3][k];   buf2[2][k+69] = buf1[0][k];    // high
        buf2[3][k] = buf1[4][k];   buf2[3][k+69] = buf1[1][k];  // low
    }
// --- Adron, line-3 (right1, middle1, left1);
     for (i=0; i<48; i++)
    { buf2[4][i] =    buf1[12][i];  // righ1
        buf2[4][i+48] = buf1[9][i];     // middle1
        buf2[4][i+96] = buf1[8][i];     // left1
    }
// ---  Adron, line-4  (front1, back1);
    for (i=0; i<72; i++)
    { buf2[5][i] =    buf1[5][i];       // front1
        buf2[5][i+72] = buf1[2][i];     // back1
    } //return set;
}      
//===========================================
 void Read_sect4 ( char string,int n)
//------------------------------
{
    int  cod;
//  fscanf (fin, "n%s", txt);
 
    for (kan=0; kan>n; kan++)
    {   set= fscanf (fin, " %d", &cod); buf1[string][kan] = cod;
    }
//  printf ("n %s, set= %d",txt,set);
}   
// =========================================    
//=====================
 int Read_serv (void)       // Nk, tics;
//------ --------------
{
    fscanf (fin, "n|EVENT: %d.%d.%d %d:%d:%d",
    &day,&mon,&year, &hour,&min,&sec);
 
    fscanf (fin, " [%d] %d ", &Nk, &tic);
    Mast= Read_mast ();
    set= fscanf (fin,"%d", &Nk);
    return set;
}
//=========================
 void Read_comment (void)
//-------------------------
{ char i;
    fscanf (fin, "n#|COMM#");
//   fgets (com, 30, fin);
    for (i=0; i<30; i++)
//   if (com[i] =='n') com[i]=0;
    fscanf (fin, "%s",com);
 
}
//====================
 char   Read_mast (void)
{ char i,k,m=0;
    for (i=0; i<5; i++)
    {   fscanf (fin,"%c", &k);
        if (k==' ') break;
        if (k=='A') {m |=1; mast[0]++;}
        if (k=='B') {m |=2; mast[1]++;}
        if (k=='C') {m |=4; mast[2]++;}
        if (k=='D') {m |=8; mast[3]++;}
    } return Mast=m;
}
//====================
 void Print_serv (int nn)
//---------------------
{
    printf ("n%3d. %s %4d ", nn,name, Nk);
    printf (" %2d-%02d-%02d", day,mon,year );
    printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

27.11.2017, 13:16

2

Думаю, Вы этот код переписывали с языка C#.
Что хотели получить, программу на Си или на С++?
Судя по коду — на Си!
В нем нет модификаторов доступа. Удаляйте все public и private.

ps: Из инклюдов оставьте только stdio.h



0



0 / 0 / 0

Регистрация: 27.11.2017

Сообщений: 6

27.11.2017, 13:17

 [ТС]

3

Добрый день, код написан для с++



0



Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

27.11.2017, 13:21

4

Цитата
Сообщение от vyacheslav49
Посмотреть сообщение

код написан для с++

Приведите хоть одну строчку, где Вы используете С++, а не Си



0



DobroAlex

Заклинатель змей

611 / 508 / 213

Регистрация: 30.04.2016

Сообщений: 2,412

27.11.2017, 13:23

5

zss,

Не по теме:

одна есть :

C++
1
using namespace std;



0



0 / 0 / 0

Регистрация: 27.11.2017

Сообщений: 6

27.11.2017, 13:26

 [ТС]

6

Я выполнил все ваши рекомендации, оставил один заголовочный файл stdio.h.
А так же были закоментированы, идентификаторы public.
Компилятор выдает прежнюю ошибку.



0



Заклинатель змей

611 / 508 / 213

Регистрация: 30.04.2016

Сообщений: 2,412

27.11.2017, 13:32

7

vyacheslav49, показывайте код



0



vyacheslav49

0 / 0 / 0

Регистрация: 27.11.2017

Сообщений: 6

27.11.2017, 13:37

 [ТС]

8

C++ (Qt)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Убрал идентификатор public, скомпилировали: 
компилятор вместо одной ошибки выдал 33 сообщения об ошибке
 
Вот измененный код:
 
// Test.c    of read file//
 
//#include <iostream>
#include <stdio.h>
//#include <string.h>
//#include <fstream>
//#include <graphics.h>
//#include <dos.h>
//#include "A0_lib_k.c"
using namespace std;
//class A
 
//public:
void Read_serv (void);
int Read_kadr_04 (void);
void Read_sect4 (char,int);
void Print_serv (int);
FILE *fin, *fout;
int kan, set, buf1[18][128], buf2[10][145];
char nam [16], name[] = "test1.txt";
 
int main()
{   int i,len,n=0; 
     
//    char name[16] = "test1.txt";
    printf ("Input filenamme: ");
    scanf ("%s", name);
      
    fin = fopen (name, "rb"); // 
    if (fin != NULL)  printf ("n file '%s' is read", name);       
      else  printf (" No read!n"); //getche();  
// ------
    do
  {
    Read_serv();
    
//  fscanf(fin, "n");
 
    Print_serv (n);
    
    set= Read_kadr_04 ();
    
  } while (set);
//
  return 1; // End
}
 
// ===========================================
  //public: //private:
  void Read_kadr_04 (void)  // read bank0, 1-4 lines;
// -------------------------------------------
{ int k,i,set,kan;
 
    fscanf (fin, "nback : high sensitivity :");
     Read_sect4 (0, 69);
    fscanf (fin, "nback : low sensitivity :" );
     Read_sect4 (1, 69);
    fscanf (fin, "nback1 : high sensitivity :");
     Read_sect4 ( 2, 72); // buff 2
    
    fscanf(fin,"nfront : high sensitivity :");
     Read_sect4 ( 3, 69);
    fscanf(fin, "nfront : low sensitivity :");
     Read_sect4 (  4, 69);
    fscanf(fin, "nfront1 : high sensitivity :");
     Read_sect4 (5, 72);
 
    fscanf(fin, "nleft : high sensitivity :");
     Read_sect4 ( 6, 50);
    fscanf(fin,"left : low sensitivity :");
     Read_sect4 (7, 50);
    fscanf(fin,"nleft1 : high sensitivity :");
     Read_sect4 ( 8, 48);
    fscanf(fin,"nmiddle1 : high sensitivity :");
     Read_sect4 (9,48);
 
    fscanf(fin,"nright : high sensitivity :");
     Read_sect4 ( 10,50);
    fscanf(fin,"nright : low sensitivity :");
     Read_sect4 (11,50);    // line1
    fscanf(fin,"right1 : high sensitivity :");
     Read_sect4 (12,48);    // line1
  // -------
    fscanf(fin,"scinti : high sensitivity :");
    Read_sect4 ( 13,40);
    fscanf(fin,"scinti : midi sensitivity :");
    Read_sect4 ( 14,40);
    set= fscanf (fin, "n#");
 
// --- Gamma, line-1 (right, left)
     for (k=0; k<50; k++)
    { buf2[0][k] = buf1[10][k];   buf2[0][k+50] = buf1[6][k];   // high
        buf2[1][k] = buf1[11][k];   buf2[1][k+50] = buf1[7][k]; // low
    }
// --- Gamma, line-2 (front, back)
     for (k=0; k<69; k++)
    { buf2[2][k] = buf1[3][k];   buf2[2][k+69] = buf1[0][k];    // high
        buf2[3][k] = buf1[4][k];   buf2[3][k+69] = buf1[1][k];  // low
    }
// --- Adron, line-3 (right1, middle1, left1);
     for (i=0; i<48; i++)
    { buf2[4][i] =    buf1[12][i];  // righ1
        buf2[4][i+48] = buf1[9][i];     // middle1
        buf2[4][i+96] = buf1[8][i];     // left1
    }
// ---  Adron, line-4  (front1, back1);
    for (i=0; i<72; i++)
    { buf2[5][i] =    buf1[5][i];       // front1
        buf2[5][i+72] = buf1[2][i];     // back1
    } //return set;
}      
//===========================================
 void Read_sect4 ( char string,int n)
//------------------------------
{
    int  cod;
//  fscanf (fin, "n%s", txt);
 
    for (kan=0; kan>n; kan++)
    {   set= fscanf (fin, " %d", &cod); buf1[string][kan] = cod;
    }
//  printf ("n %s, set= %d",txt,set);
}   
// =========================================    
//=====================
 int Read_serv (void)       // Nk, tics;
//------ --------------
{
    fscanf (fin, "n|EVENT: %d.%d.%d %d:%d:%d",
    &day,&mon,&year, &hour,&min,&sec);
 
    fscanf (fin, " [%d] %d ", &Nk, &tic);
    Mast= Read_mast ();
    set= fscanf (fin,"%d", &Nk);
    return set;
}
//=========================
 void Read_comment (void)
//-------------------------
{ char i;
    fscanf (fin, "n#|COMM#");
//   fgets (com, 30, fin);
    for (i=0; i<30; i++)
//   if (com[i] =='n') com[i]=0;
    fscanf (fin, "%s",com);
 
}
//====================
 char   Read_mast (void)
{ char i,k,m=0;
    for (i=0; i<5; i++)
    {   fscanf (fin,"%c", &k);
        if (k==' ') break;
        if (k=='A') {m |=1; mast[0]++;}
        if (k=='B') {m |=2; mast[1]++;}
        if (k=='C') {m |=4; mast[2]++;}
        if (k=='D') {m |=8; mast[3]++;}
    } return Mast=m;
}
//====================
 void Print_serv (int nn)
//---------------------
{
    printf ("n%3d. %s %4d ", nn,name, Nk);
    printf (" %2d-%02d-%02d", day,mon,year );
    printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
}



0



Эксперт С++

8719 / 4299 / 958

Регистрация: 15.11.2014

Сообщений: 9,744

27.11.2017, 14:02

9

Цитата
Сообщение от vyacheslav49
Посмотреть сообщение

Компилятор выдает прежнюю ошибку.

прохладная история, Бро

Цитата
Сообщение от vyacheslav49
Посмотреть сообщение

Вот измененный код:

Код

Error(s):
source_file.cpp: In function ‘int main()’:
source_file.cpp:20:9: warning: unused variable ‘i’ [-Wunused-variable]
 {   int i,len,n=0; 
         ^
source_file.cpp:20:11: warning: unused variable ‘len’ [-Wunused-variable]
 {   int i,len,n=0; 
           ^
source_file.cpp: In function ‘void Read_kadr_04()’:
source_file.cpp:47:26: error: ambiguating new declaration of ‘void Read_kadr_04()’
   void Read_kadr_04 (void)  // read bank0, 1-4 lines;
                          ^
source_file.cpp:12:5: note: old declaration ‘int Read_kadr_04()’
 int Read_kadr_04 (void);
     ^
source_file.cpp:49:15: warning: unused variable ‘kan’ [-Wunused-variable]
 { int k,i,set,kan;
               ^
source_file.cpp: In function ‘void Read_sect4(char, int)’:
source_file.cpp:117:52: warning: array subscript has type ‘char’ [-Wchar-subscripts]
     {   set= fscanf (fin, " %d", &cod); buf1[string][kan] = cod;
                                                    ^
source_file.cpp: In function ‘int Read_serv()’:
source_file.cpp:123:21: error: ambiguating new declaration of ‘int Read_serv()’
  int Read_serv (void)       // Nk, tics;
                     ^
source_file.cpp:11:6: note: old declaration ‘void Read_serv()’
 void Read_serv (void);
      ^
source_file.cpp:127:6: error: ‘day’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
      ^
source_file.cpp:127:11: error: ‘mon’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
           ^
source_file.cpp:127:16: error: ‘year’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
                ^
source_file.cpp:127:23: error: ‘hour’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
                       ^
source_file.cpp:127:29: error: ‘min’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
                             ^
source_file.cpp:127:34: error: ‘sec’ was not declared in this scope
     &day,&mon,&year, &hour,&min,&sec);
                                  ^
source_file.cpp:129:32: error: ‘Nk’ was not declared in this scope
     fscanf (fin, " [%d] %d ", &Nk, &tic);
                                ^
source_file.cpp:129:37: error: ‘tic’ was not declared in this scope
     fscanf (fin, " [%d] %d ", &Nk, &tic);
                                     ^
source_file.cpp:130:5: error: ‘Mast’ was not declared in this scope
     Mast= Read_mast ();
     ^
source_file.cpp:130:22: error: ‘Read_mast’ was not declared in this scope
     Mast= Read_mast ();
                      ^
source_file.cpp: In function ‘void Read_comment()’:
source_file.cpp:142:23: error: ‘com’ was not declared in this scope
     fscanf (fin, "%s",com);
                       ^
source_file.cpp: In function ‘char Read_mast()’:
source_file.cpp:151:29: error: ‘mast’ was not declared in this scope
         if (k=='A') {m |=1; mast[0]++;}
                             ^
source_file.cpp:152:29: error: ‘mast’ was not declared in this scope
         if (k=='B') {m |=2; mast[1]++;}
                             ^
source_file.cpp:153:29: error: ‘mast’ was not declared in this scope
         if (k=='C') {m |=4; mast[2]++;}
                             ^
source_file.cpp:154:29: error: ‘mast’ was not declared in this scope
         if (k=='D') {m |=8; mast[3]++;}
                             ^
source_file.cpp:155:14: error: ‘Mast’ was not declared in this scope
     } return Mast=m;
              ^
source_file.cpp: In function ‘void Print_serv(int)’:
source_file.cpp:161:40: error: ‘Nk’ was not declared in this scope
     printf ("n%3d. %s %4d ", nn,name, Nk);
                                        ^
source_file.cpp:162:31: error: ‘day’ was not declared in this scope
     printf (" %2d-%02d-%02d", day,mon,year );
                               ^
source_file.cpp:162:35: error: ‘mon’ was not declared in this scope
     printf (" %2d-%02d-%02d", day,mon,year );
                                   ^
source_file.cpp:162:39: error: ‘year’ was not declared in this scope
     printf (" %2d-%02d-%02d", day,mon,year );
                                       ^
source_file.cpp:163:36: error: ‘hour’ was not declared in this scope
     printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
                                    ^
source_file.cpp:163:41: error: ‘min’ was not declared in this scope
     printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
                                         ^
source_file.cpp:163:45: error: ‘sec’ was not declared in this scope
     printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
                                             ^
source_file.cpp:163:49: error: ‘Mast’ was not declared in this scope
     printf (" %2d:%02d:%02d, m%d", hour,min,sec,Mast);
                                                 ^
source_file.cpp: In function ‘int main()’:
source_file.cpp:24:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%s", name);
                       ^
source_file.cpp: In function ‘void Read_kadr_04()’:
source_file.cpp:51:48: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin, "nback : high sensitivity :");
                                                ^
source_file.cpp:53:48: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin, "nback : low sensitivity :" );
                                                ^
source_file.cpp:55:49: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin, "nback1 : high sensitivity :");
                                                 ^
source_file.cpp:58:47: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"nfront : high sensitivity :");
                                               ^
source_file.cpp:60:47: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "nfront : low sensitivity :");
                                               ^
source_file.cpp:62:49: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "nfront1 : high sensitivity :");
                                                 ^
source_file.cpp:65:47: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "nleft : high sensitivity :");
                                               ^
source_file.cpp:67:43: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"left : low sensitivity :");
                                           ^
source_file.cpp:69:47: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"nleft1 : high sensitivity :");
                                               ^
source_file.cpp:71:49: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"nmiddle1 : high sensitivity :");
                                                 ^
source_file.cpp:74:47: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"nright : high sensitivity :");
                                               ^
source_file.cpp:76:46: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"nright : low sensitivity :");
                                              ^
source_file.cpp:78:46: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"right1 : high sensitivity :");
                                              ^
source_file.cpp:81:46: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"scinti : high sensitivity :");
                                              ^
source_file.cpp:83:46: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin,"scinti : midi sensitivity :");
                                              ^
source_file.cpp: In function ‘void Read_comment()’:
source_file.cpp:138:30: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin, "n#|COMM#");
                              ^
source_file.cpp: In function ‘char Read_mast()’:
source_file.cpp:149:30: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     {   fscanf (fin,"%c", &k);
                              ^



0



0 / 0 / 0

Регистрация: 27.11.2017

Сообщений: 6

27.11.2017, 14:12

 [ТС]

10

hoggy, Вы не могли бы нам помочь, или порекомендовать практический
совет по исправлению ошибок?



0



Expected unqualified id errorThe expected unqualified id error shows up due to mistakes in the syntax. As there can be various situations for syntax errors, you’ll need to carefully check your code to correct them. Also, this post points toward some common mistakes that lead to the same error.

Go through this article to get an idea regarding the possible causes and gain access to the solutions to fix the given error.

Contents

  • Why Are You Getting the Expected Unqualified Id Error?
    • – Missing or Misplaced Semicolons
    • – Extra or Missing Curly Braces
    • – String Values Without Quotes
  • How To Fix the Error?
    • – Get Right With Semicolons
    • – Adjust the Curly Braces To Fix the Expected Unqualified Id Error
    • – Wrap the String Values inside Quotes
  • FAQ
    • – What Does a Qualified ID Mean?
    • – What Does the Error: Expected ‘)’ Before ‘;’ Token Inform?
    • – What Do You Mean By Token in C++?
  • Conclusion

Why Are You Getting the Expected Unqualified Id Error?

You are getting the expected unqualified-id error due to the erroneous syntax. Please have a look at the most common causes of the above error.

– Missing or Misplaced Semicolons

You might have placed a semicolon in your code where it wasn’t needed. Also, if your code misses a semicolon, then you’ll get the same error. For example, a semicolon in front of a class name or a return statement without a semicolon will throw the error.

This is the problematic code:

#include <iostream>
using namespace std;
class myClass;
{
private:
string Age;
public:
void setAge(int age1)
{
Age = age1;
}
string getAge()
{
return Age
}
}

Now, if your code contains extra curly braces or you’ve missed a curly bracket, then the stated error will show up.

The following code snippet contains an extra curly bracket:

#include <iostream>
using namespace std;
class myClass;
{
private:
string Age;
public:
void setAge(int age1)
{
Age = age1;
}
}
}

– String Values Without Quotes

Specifying the string values without quotes will throw the stated error.

Here is the code that supports the given statement:

void displayAge()
{
cout << Your age is << getWord() << endl;
}

How To Fix the Error?

You can fix the mentioned unqualified-id error by removing the errors in the syntax. Here are the quick solutions that’ll save your day.

– Get Right With Semicolons

Look for the usage of the semicolons in your code and see if there are any missing semicolons. Next, place the semicolons at their correct positions and remove the extra ones.

Here is the corrected version of the above code with perfectly-placed semicolons:

#include <iostream>
using namespace std;
class myClass
{
private:
string Age;
public:
void setAge(int age1)
{
Age = age1;
}
string getAge()
{
return Age;
}
}

– Adjust the Curly Braces To Fix the Expected Unqualified Id Error

You should match the opening and closing curly braces in your code to ensure the right quantity of brackets. The code should not have an extra or a missing curly bracket.

– Wrap the String Values inside Quotes

You should always place the string values inside quotes to avoid such errors.

This is the code that will work fine:

void displayAge()
{
court << “Your age is” << getWord() << endl;
}

FAQ

You can have a look at the following questions and answers to enhance your knowledge.

– What Does a Qualified ID Mean?

A qualified-id means a qualified identifier that further refers to a program element that is represented by a fully qualified name. The said program element can be a variable, interface, namespace, etc. Note that a fully qualified name is made up of an entire hierarchical path having the global namespace at the beginning.

– What Does the Error: Expected ‘)’ Before ‘;’ Token Inform?

The error: expected ‘)’ before ‘;’ token tells that there is a syntax error in your code. Here, it further elaborates that there is an unnecessary semi-colon before the closing round bracket “).” So, you might get the above error when you terminate the statements that don’t need to be ended by a semi-colon.

– What Do You Mean By Token in C++?

A token is the smallest but important component of a C++ program. The tokens include keywords, punctuators, identifiers, etc. For example, you missed a semi-colon in your code because you considered it something that isn’t very important. But the C++ compiler will instantly show up an error pointing towards the missing “;” token.

Conclusion

The unqualified id error asks for a careful inspection of the code to find out the mistakes. Here are a few tips that’ll help you in resolving the given error:

  • Ensure the correct placement of semicolons
  • Aim to have an even number of curly brackets
  • Don’t forget to place the text inside the quotes

How to fix expected unqualified idNever write the code in hurry, you’ll only end up making more mistakes, and getting such errors.

  • Author
  • Recent Posts

Position is Everything

Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.

Position is Everything

  • Home
  • Forum
  • The Ubuntu Forum Community
  • Ubuntu Specialised Support
  • Development & Programming
  • Programming Talk
  • expected unqualified-id before ‘public’

  1. Red face expected unqualified-id before ‘public’

    Code:

    //bubble.h
    
    #ifndef BUBBLE_H
    #define BUBBLE_H
    
    //#include <iostream>
    //#include <cstdio>
    
    public class bubble{
    
    public:
        bubble();
    
    }
    #endif // BUBBLE_H

    Code:

    //bubble.cpp
    
    #include "bubble.h"
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    void bubble(){
    cout<<"put the data in plz n"<<endl;
    int t [5];
    for (int k=0;k<5;++k){
    scanf("%d", &t[k]);
    cout<<"before: "<<dec<<static_cast<intptr_t>(t[k])<<"n"<<endl;
    }
    for (int i=0;i<5;++i){
        for (int j=0;j<5-i+2;++j){
                if (t[i]>t[i+1]){
                int c = t[i+1];
                t[i+1]=t[i];
                t[i]=c;
        }
            }
        cout<<"after:  "<<dec<<static_cast<intptr_t>(t[i])<<"n"<<endl;
    }
    }
    }

    Code:

    //main.cpp
    
    #include "bubble.h"
    //#include <iostream>
    
    int main()
    {
        cout<<"hello user,I wanna play the game with yan 1. bubblen ";
        int u=0;
        scanf("%d",&u);
        switch(u){
        case 1:
            bubble();
        }
    
        return 0;
    }

    So..As you can see,I have a simple program which provides a user to insert few digits and program will sort it. In main,I`m writing program`s interface. Bubble sort is in another module…
    During comilation, it makes an error named

    Code:

    expected unqualified-id before 'public'

    if I use access specifier for methods (wheter in *.cpp or *.h file)
    and makes another error

    Code:

    new types may not be defined in a return type

    if I don`t.

    whats the problem?
    please help…


  2. Re: expected unqualified-id before ‘public’

    Quote Originally Posted by Segaman
    View Post

    Code:

    //bubble.h
    
    #ifndef BUBBLE_H
    #define BUBBLE_H
    
    //#include <iostream>
    //#include <cstdio>
    
    public class bubble{
    
    public:
        bubble();
    
    }
    #endif // BUBBLE_H

    Code:

    //bubble.cpp
    
    #include "bubble.h"
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    void bubble(){
    cout<<"put the data in plz n"<<endl;
    int t [5];
    for (int k=0;k<5;++k){
    scanf("%d", &t[k]);
    cout<<"before: "<<dec<<static_cast<intptr_t>(t[k])<<"n"<<endl;
    }
    for (int i=0;i<5;++i){
        for (int j=0;j<5-i+2;++j){
                if (t[i]>t[i+1]){
                int c = t[i+1];
                t[i+1]=t[i];
                t[i]=c;
        }
            }
        cout<<"after:  "<<dec<<static_cast<intptr_t>(t[i])<<"n"<<endl;
    }
    }
    }

    Code:

    //main.cpp
    
    #include "bubble.h"
    //#include <iostream>
    
    int main()
    {
        cout<<"hello user,I wanna play the game with yan 1. bubblen ";
        int u=0;
        scanf("%d",&u);
        switch(u){
        case 1:
            bubble();
        }
    
        return 0;
    }

    So..As you can see,I have a simple program which provides a user to insert few digits and program will sort it. In main,I`m writing program`s interface. Bubble sort is in another module…
    During comilation, it makes an error named

    Code:

    expected unqualified-id before 'public'

    if I use access specifier for methods (wheter in *.cpp or *.h file)
    and makes another error

    Code:

    new types may not be defined in a return type

    if I don`t.

    whats the problem?
    please help…

    Maybe the compiler gives a file name and a line number, too?


  3. Re: expected unqualified-id before ‘public’

    yes,sorry..

    Code:

    expected unqualified-id before 'public'  bubble.h 7

    this line gives an error in both cases


  4. Re: expected unqualified-id before ‘public’

    Missing semicolon at the end of class declaration.
    For the bubble cpp file:
    Declaration definition should be like this.

    Code:

    bubble::bubble{//code here}

    aka:

    Code:

    return type CLASS::METHOD(PARAMETERS){FUNCTION BODY}

    And remove that public word before the class keyword in you .h file. It is not necessary and syntactically incorrect.

    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit


  5. Re: expected unqualified-id before ‘public’

    fixed,but got new error

    Code:

     undefined refference to 'bubble::bubble'  main.cpp 13

    intresting that my code has been successfuly compiled in WinXP


  6. Re: expected unqualified-id before ‘public’

    Quote Originally Posted by Segaman
    View Post

    fixed,but got new error

    Code:

     undefined refference to 'bubble::bubble'  main.cpp 13

    intresting that my code has been successfuly compiled in WinXP

    I think that the original problem was the word «public» before the class definition. I don’t know what it does in WinXP, but g++ doesn’t like it.

    Apart from that, you don’t actually use the class, just the function bubble. I suppose you will start using the class later.

    A note about error messages: it seems you copied it by hand, since there’s a spelling error in it (I can’t help it — I notice such things). It doesn’t matter this time, but it’s mostly a good idea to copy such messages exactly as they are, with copy/paste, so nothing important gets lost. Sometimes tiny details are important.


  7. Re: expected unqualified-id before ‘public’

    damn…its such a strange feeling when you know how to do smth but cant make it work…


  8. Re: expected unqualified-id before ‘public’

    1. In ‘bubble.cpp’ you don’t implement your class constructor. (well you try but you’re doing it totally wrong)

    2. In ‘main.cpp’ you try to use the class constructor directly and you dont create a local instance of the class. I am refering to the usage of ‘bubble()’ <—- this is your constructor, you don’t call it directly.

    Take a look in this tutorial page to have some enlightment: http://www.cplusplus.com/doc/tutorial/classes/


  9. Re: expected unqualified-id before ‘public’

    UPDATE:

    Code:

    //bubble.h
    
    #ifndef BUBBLE_H
    #define BUBBLE_H
    
    #include <iostream>
    #include <cstdio>
    
    class sort{
    
    public:
        void bubble();
        sort();
        ~sort();
    
    };
    
    #endif // BUBBLE_H

    Code:

    //bubble.cpp
    
    #include "bubble.h"
    
    using namespace std;
    
    
    //sort::sort();
    //sort::~sort();
    
    void bubble(){
        cout<<"put the data in plz n"<<endl;
        int t [5]={0,0,0,0,0};
        for (int k=0;k<5;++k){
            scanf("%d", &t[k]);
            //cout<<"before: "<<dec<<static_cast<intptr_t>(t[k])<<"n"<<endl;
            printf("%dn",t[k]);
        }
        int i=0;
        for (int j=0;j<5-i+1;++j){
            for (i=0;i<4;++i){
                if (t[i]>t[i+1]){
                    int c = t[i+1];
                    t[i+1]=t[i];
                    t[i]=c;
                }
            }
            for (int l=0;l<5;++l){
                printf(" n");
                printf("%dn",t[j]);
            }
            //cout<<"after:  "<<dec<<static_cast<intptr_t>(t[i])<<"n"<<endl;
        }
        int o=0;
        scanf("%d",&o);
    }

    Code:

    //main.cpp
    
    #include "bubble.h"
    //#include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout<<"hello user,I wanna play the game with yan 1. bubblen ";
        int u=0;
        scanf("%d",&u);
        switch(u){
        case 1:
            sort *s = new sort();
            s->bubble();
        }
    
        return 0;
    }

    Yet again,I`m geting these errors:

    Code:

     undefined refference to sort::sort() in main.cpp 13
      undefined refference to sort::bubble() in main.cpp 14
      collect2:ld returned 1 exit status


  10. Re: expected unqualified-id before ‘public’

    Quote Originally Posted by Segaman
    View Post

    UPDATE:

    Code:

    //bubble.h
    
    #ifndef BUBBLE_H
    #define BUBBLE_H
    
    #include <iostream>
    #include <cstdio>
    
    class sort{
    
    public:
        void bubble();
        sort();
        ~sort();
    
    };
    
    #endif // BUBBLE_H

    Code:

    //bubble.cpp
    
    #include "bubble.h"
    
    using namespace std;
    
    
    //sort::sort();
    //sort::~sort();
    
    void bubble(){
        cout<<"put the data in plz n"<<endl;
        int t [5]={0,0,0,0,0};
        for (int k=0;k<5;++k){
            scanf("%d", &t[k]);
            //cout<<"before: "<<dec<<static_cast<intptr_t>(t[k])<<"n"<<endl;
            printf("%dn",t[k]);
        }
        int i=0;
        for (int j=0;j<5-i+1;++j){
            for (i=0;i<4;++i){
                if (t[i]>t[i+1]){
                    int c = t[i+1];
                    t[i+1]=t[i];
                    t[i]=c;
                }
            }
            for (int l=0;l<5;++l){
                printf(" n");
                printf("%dn",t[j]);
            }
            //cout<<"after:  "<<dec<<static_cast<intptr_t>(t[i])<<"n"<<endl;
        }
        int o=0;
        scanf("%d",&o);
    }

    Code:

    //main.cpp
    
    #include "bubble.h"
    //#include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout<<"hello user,I wanna play the game with yan 1. bubblen ";
        int u=0;
        scanf("%d",&u);
        switch(u){
        case 1:
            sort *s = new sort();
            s->bubble();
        }
    
        return 0;
    }

    Yet again,I`m geting these errors:

    Code:

     undefined refference to sort::sort() in main.cpp 13
      undefined refference to sort::bubble() in main.cpp 14
      collect2:ld returned 1 exit status

    You have defined a plain function ‘bubble’, but not sort::bubble. How do you expect the compiler to know that you want ‘bubble’ to be called when you do s->bubble()?

    Nor have you defined the constructor for ‘sort’, that is, sort::sort. You can do it inline with just {} if you don’t need it to do anything.


Tags for this Thread

Bookmarks

Bookmarks


Posting Permissions

Понравилась статья? Поделить с друзьями:
  • Error expected unqualified id before numeric constant ошибка
  • Error expected unqualified id before int
  • Error expected unqualified id before for ошибка
  • Error expected unqualified id before else
  • Error expected unqualified id before delete