[Error] expected unqualified-id before '{' token tell me how to solve "{" error

#include<iostream>
#include<conio.h>
using namespace std;
class second;
class first;
{
int a,b;
public :
void get ()
{
cout<<"\n enter a&b";
cin>>a>>b;
}
void show()
{
cout<<"\n"<<a<<b;
}
void swap (second &)
}
class second;
{
int x,y;
public:
void get()
{
cout<<"\n enter x&y";
cin>>X>>y;
}
void show()
{
cout<<"\n"<<x<<y;
}
friend void first::swap(second &;)
};
void first::swap(second & s)
{
int t;
t=a; a=s.x; s.x=t;
t=b; b=s.y; s.y=t;
};
void main()
{
first f1;
second s1;
f1.get();
s1.get();
f1.show();
s1.show();
f1.swap(s1);
f1.show();
s1.show();
return 0
};
Last edited on
i m try many things but this error appear in my every programm when i go compile so i m not able tp complete any programm.
The error message is a bit cryptic but it means that it expects an identifier (a name) before the { symbol.
If you look at what's before the { symbol (on the line above) you find that there is a semicolon that shouldn't be there.
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

It would be so much easier for both you and us to see the problems with your code if it were properly formatted.

2) The following lines look dodgy to me:

1
2
void swap (second &)
}

I suspect there's a missing semicolon there.

3) In the following lines:

1
2
class first;
{

That semicolon shouldn't be there.

i m try many things but this error appear in my every programm when i go compile so i m not able tp complete any programm.

That probably means there's something fundamental about C++ syntax that you haven't understood and learnt, so you're making the same mistakes over and over.

From the looks of the errors I have spotted, it looks as though you haven't properly learned the syntax for class definitions, method declarations, and method definitions. In particular, you should learn where you need to put semicolons, and where you need to not put semicolons.
Last edited on
thanks to tell me but when i do change but my expected unqualified-id before '{' token error not gone. and when i remove class first ; semicolon so its give another error.[Error] expected ';' after class definition. when i put again that semicolon so its solve.
Last edited on
There are many errors in the program (most of them very minor).
A couple of examples: return 0 semicolon missing
cin>>X>>y; x should be lower-case.

Most of the issues are of that nature (too many or too few semicolons).

You need to work through them one by one, using the compiler messages as a guide.

Line 5,20: Extraneous ;
Line 18: Missing a ; (or a function body)
Line 19: Missing ; to terminate the class.
Line 27: Capitalization error.
Line 33: ; belongs after the ), not before
Line 40,53: Extraneous ;
Line 41: main() must be type int
Line 52: Missing ;

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
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
[code]#include<iostream>
#include<conio.h>
using namespace std;
class second;
class first;
{
int a,b;
public :
void get ()
{
cout<<"\n enter a&b";
cin>>a>>b;
}
void show()
{
cout<<"\n"<<a<<b;
}
void swap (second &)
}
class second;
{
int x,y;
public:
void get()
{
cout<<"\n enter x&y";
cin>>X>>y;
}
void show()
{
cout<<"\n"<<x<<y;
}
friend void first::swap(second &;)
};
void first::swap(second & s)
{
int t;
t=a; a=s.x; s.x=t;
t=b; b=s.y; s.y=t;
};
void main()
{
first f1;
second s1;
f1.get();
s1.get();
f1.show();
s1.show();
f1.swap(s1);
f1.show();
s1.show();
return 0
};
[/code]
ok now only tell me what semicolon i erase and where i put semicolon to correct this programme. i want to know and learn how i sovle expected unqualified-id before '{' token error.
thanks for help.
Last edited on
A couple of examples: return 0 semicolon missing
cin>>X>>y; x should be lower-case.

I pointed out these two errors two days ago, but they are still not fixed. I think you should at least make some effort to follow the help given by others such as AbstractionAnon too. The code won't magically fix itself if you're not prepared to even try.
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
#include<iostream>
#include<conio.h>
using namespace std;
class second;
class first;
{
  int a,b;
  public :
  void get ()
{
  cout<<"\n enter a&b";
  cin>>a>>b;
  }
  void show()
  {
  cout<<"\n"<<a<<b;
  }
  void swap(second &);
  };
 class second;
{
int x,y;
public:
void get()
{
cout<<"\n enter x&y";
cin>>x>>y;
}
void show()
{
cout<<"\n"<<x<<y;
}
friend void first::swap(second &);
};
void first::swap(second & s)
{
int t;
t=a; a=s.x; s.x=t;
t=b; b=s.y; s.y=t;
};
void main(int)
{
first f1;
second s1;
f1.get();
s1.get();
f1.show();
s1.show();
f1.swap(s1);
f1.show();
s1.show();
return 0;
};
like u said chervil. i change many things and its help. but my first error still there. its point curser line 6 and 19 line. expected unqualified-id before '{' token error. so i try many other token but i don't understand which token id its taking about.
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
#include<iostream>
// #include<conio.h>
using namespace std ;

class second;

class first // ; *** remove the semicolon here
{
    int a,b;
public :
    void get ()
    {
        cout<<"\n enter a&b";
        cin>>a>>b;
    }
    void show()
    {
        cout<<"\n"<<a<<b;
    }
    void swap(second &);
};

class second // ; *** remove the semicolon here
{
    int x,y;
public:
    void get()
    {
        cout<<"\n enter x&y";
        cin>>x>>y;
    }
    void show()
    {
        cout<<"\n"<<x<<y;
    }
    friend void first::swap(second &);
};

void first::swap(second & s)
{
    int t;
    t=a;
    a=s.x;
    s.x=t;
    t=b;
    b=s.y;
    s.y=t;
} // ; *** remove the semicolon here

// void main(int)
int main() // main must return int
{
    first f1;
    second s1;
    f1.get();
    s1.get();
    f1.show();
    s1.show();
    f1.swap(s1);
    f1.show();
    s1.show();
    return 0;
}
thanks to all and thanks jL becaus u tell me things very clearly with comment so i understand and now my programme compile without error thanks.

can u tell me i put semicolon class first and class second that's why he give me unqualified-id before '{' token error. because i want to know so if that error appear again in my other programme so i m able to solve it. thanks
Last edited on
You need to understand the difference between a class definition, and a forward declaration of a class. Your textbook should clearly show the difference in syntax, and, specifically, where to put semicolons in each case.
Declare class first: class first; // terminate the declaration with a semicolon

Define class first:
1
2
3
4
5
6
class first
{

    // ....

}; // terminate the definition with a semicolon 
now i understand
Topic archived. No new replies allowed.