473,472 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

too many types in declaration

1 New Member
it is a simple program that is demonstrating class and object.but it is giving an error like too many types in declaration and function should return a value....
pls find solution and suggest me what should i do...

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4. class ayes
  5. {
  6. public:
  7. void foo()
  8. {
  9. int a,b;
  10. cout<<"Enter two nos:";
  11. cin>>a>>b;
  12. cout<<a+b;
  13. }
  14. }
Jun 21 '11 #1
3 17080
code green
1,726 Recognized Expert Top Contributor
public: preceds a list of member variables and class declarations.
You have not listed any so the following function is being read as such.
Jun 21 '11 #2
Banfa
9,065 Recognized Expert Moderator Expert
@code green, it is completely acceptable in language syntax to place the body of a method inside a class declaration as has been done, although it is normally reserved for short methods as methods declared like that are automatically inlined.

@AYESHA Jabeen, you use iostream.h, this header was deprecated in 1999 with the release of the C++ standard. You should be using iostream (note no .h). conio.h is not a standard header and you don't seem to be using anything from it either. If you do switch headers remember you will need to access the std name space to reference cin and cout.

You are missing a ; on line 14. Part from that I see little wrong and it compiles with that error fixed.
Jun 21 '11 #3
jaseel97
16 New Member
Put semicolon after the class declaration. That should do the trick.
Feb 6 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
3
by: crichmon | last post by:
Any general advice for dealing with circular dependencies? For example, I have a situation which, when simplified, is similar to: ///////////// // A.h class A { public: int x;
2
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying...
4
by: j0mbolar | last post by:
What is the chapter and verse for the following? #include <stdio.h> void foo(struct bar *baz); struct bar { int x, y; };
9
by: Michael Mair | last post by:
Hello, in C89 (at least in the last public draft), "3.6.2 Compound statement, or block", we have ,--- | Syntax | | compound-statement: | { ...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
58
by: jacob navia | last post by:
Hi people I have been working again in my tutorial, and I have finished the "types" chapter. If you feel like "jacob bashing" this is the occasion! I am asking for criticisms, or for things I may...
14
by: Lane Straatman | last post by:
I would like to write a 'struct'. I have a library that is all but completely inappropriate for this task. So I'm looking for C code that fills in the gaps between: #undef...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
3
Fr33dan
by: Fr33dan | last post by:
I'm a long time Java guy trying to move to C++ but I keep getting this error that I can't seem to figure out. It must be something simple I'm missing but I can't find it by looking at examples. I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.