![]() |
|
#1
|
|||
|
|||
Trouble with user defined classesI have written the following code for a header file, the class file, and a driver file:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
I get the following error messages: Code:
|
|||
|
#2
|
|||
|
|||
Re: trouble with user defined classesQuote:
Put a semicolon after the closing brace of the class definition in counter.h Regards, Dave Last edited by davekw7x : 24-Mar-2008 at 08:04.
|
|
#3
|
|||
|
|||
Re: Trouble with user defined classesOk now I get this error message:
Code:
|
|
#4
|
||||
|
||||
Re: Trouble with user defined classesYou might want to check whatever material that you are using to learn about classes, and seek information about a 'constructor' and its purpose.
That error is complaining about this line: CPP / C++ / C Code:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#5
|
|||
|
|||
Re: Trouble with user defined classesI just needed to use the "resetCount()" function to initialize the the object "myCount"
|
|
#6
|
|||
|
|||
Re: Trouble with user defined classesQuote:
Now, the error you reported in your first post might have confused anyone. But for this one: Look (yes look) at the message: Quote:
Now look at the line that it is complaining about: CPP / C++ / C Code:
myCount is not an integer data type or any other kind of data type that can be initialized with an integer value. If you want to make sure that myCount has a counter value equal to zero when it is created, you can make a constructor that sets the object member count equal to zero. Regards, Dave Footnote: I know that when you are just getting started, error messages from compilers can be intimidating. You have to get used to seeing and dealing with them. I mean, it's always OK to ask, but it might be quicker to try to puzzle it out on your own. After all: "No one was born knowing this stuff, you know." ---davekw7x |
|
#7
|
|||
|
|||
Re: Trouble with user defined classesQuote:
I think that, in general, it is not good program design to allow an object to be created in an unknown state. Use a constructor that sets the value. Default value of zero is probably a Good Thing for this particular class. Regards, Dave |
Recent GIDBlog
Updates On The All New Toyota VIOS - Part III by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Candy machine simulation (m0g0l) | cplus2x | CPP / C++ Forum | 1 | 07-Feb-2008 05:21 |
| passing locally defined user type to function from function | earachefl | CPP / C++ Forum | 1 | 01-Jul-2006 17:54 |
| how to access User defined functions of my View class to MainFrm class? | prabhakar157 | MS Visual C++ / MFC Forum | 1 | 17-May-2006 03:09 |
| User defined headers | davis | Miscellaneous Programming Forum | 6 | 16-Feb-2006 18:40 |
| [C++]Structures and Classes | redthestudent | CPP / C++ Forum | 12 | 31-Jul-2005 08:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The