vyacheslav49 0 / 0 / 0 Регистрация: 27.11.2017 Сообщений: 6 |
||||
1 |
||||
27.11.2017, 13:10. Показов 3996. Ответов 9 Метки нет (Все метки)
Добрый день коллеги! Исходный код программы:
__________________
0 |
Модератор 12641 / 10135 / 6102 Регистрация: 18.12.2011 Сообщений: 27,170 |
|
27.11.2017, 13:16 |
2 |
Думаю, Вы этот код переписывали с языка C#. 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 |
код написан для с++ Приведите хоть одну строчку, где Вы используете С++, а не Си
0 |
DobroAlex Заклинатель змей 611 / 508 / 213 Регистрация: 30.04.2016 Сообщений: 2,412 |
||||
27.11.2017, 13:23 |
5 |
|||
zss, Не по теме: одна есть :
0 |
0 / 0 / 0 Регистрация: 27.11.2017 Сообщений: 6 |
|
27.11.2017, 13:26 [ТС] |
6 |
Я выполнил все ваши рекомендации, оставил один заголовочный файл stdio.h.
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 |
|||
0 |
8719 / 4299 / 958 Регистрация: 15.11.2014 Сообщений: 9,744 |
|
27.11.2017, 14:02 |
9 |
Компилятор выдает прежнюю ошибку. прохладная история, Бро
Вот измененный код: Код 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 |
The 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
Never write the code in hurry, you’ll only end up making more mistakes, and getting such errors.
- Author
- Recent Posts
Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.
- Forum
- The Ubuntu Forum Community
- Ubuntu Specialised Support
- Development & Programming
- Programming Talk
- expected unqualified-id before ‘public’
-
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 namedCode:
expected unqualified-id before 'public'
if I use access specifier for methods (wheter in *.cpp or *.h file)
and makes another errorCode:
new types may not be defined in a return type
if I don`t.
whats the problem?
please help…
-
Re: expected unqualified-id before ‘public’
Originally Posted by Segaman
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 namedCode:
expected unqualified-id before 'public'
if I use access specifier for methods (wheter in *.cpp or *.h file)
and makes another errorCode:
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?
-
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
-
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
-
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
-
Re: expected unqualified-id before ‘public’
Originally Posted by Segaman
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.
-
Re: expected unqualified-id before ‘public’
damn…its such a strange feeling when you know how to do smth but cant make it work…
-
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/
-
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
-
Re: expected unqualified-id before ‘public’
Originally Posted by Segaman
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.