| | |
code fixing
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
I don't usually ask for help on these but I missed a day of class and I'm a bit out of the loop. We're going over structures and for HW my instructer likes to do code fixes where theres code with errors that we need to correct. Anyways, I'm reading through my book and I'm not finding any examples that are similar to this problem so I'm not sure what exactly I need to do to correct it. Theres nothing so far that has a void function inside of a structure, with the main called the function.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; struct ThreeVals { int a, b, c; void ThreeVals() {a = 1; b = 2; c = 3;} }; int main() { ThreeVals vals; cout << vals << endl; return 0; }
Well, you could start by reading the compiler error messages, they will at least point you to (or near) the places that need fixing.
Read your textbook for the examples of how structures/classes should look - what's the difference compared to your problem?
Read your textbook for the examples of how structures/classes should look - what's the difference compared to your problem?
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
errors are:
error C2380: type(s) preceding 'ThreeVals' (constructor with return type, or illegal redefinition of current class-name?)
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct ThreeVals' (or there is no acceptable conversion)
And I already said that I looked in my text book. I can't find anything in the section that has a void function in the structure. I don't know if there's special rules or what not. I just see normal structures that declare ints doubles, and strings.
And I don't know what the errors mean. I'm looking through my book, but like I said there's no examples that are similar to this. I've already fixed one set of code and am working on another. This one just bugs me.
error C2380: type(s) preceding 'ThreeVals' (constructor with return type, or illegal redefinition of current class-name?)
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct ThreeVals' (or there is no acceptable conversion)
And I already said that I looked in my text book. I can't find anything in the section that has a void function in the structure. I don't know if there's special rules or what not. I just see normal structures that declare ints doubles, and strings.
And I don't know what the errors mean. I'm looking through my book, but like I said there's no examples that are similar to this. I've already fixed one set of code and am working on another. This one just bugs me.
The first one is not something we do in something that is strictly a struct. If your text has another section dealing with classes, look at the explanation of a constructor, and how it's implemented. It's a function, but not written exactly like the functions you've written up to this point.
The second one means that there's no way (at the moment) to directly output the contents of your struct. You have to display it one member at a time. This, I'm sure, is covered in your text. (Look for the "dot operator" )
The second one means that there's no way (at the moment) to directly output the contents of your struct. You have to display it one member at a time. This, I'm sure, is covered in your text. (Look for the "dot operator" )
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Okay, I made ThreeVals not a void function and it seems to have worked. Tell me if this is correct or not please.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; struct ThreeVals { int a, b, c; ThreeVals() { a = 1; b = 2; c = 3; } }; int main() { ThreeVals vals; cout << vals.a << vals.b << vals.c << endl; return 0; }
Last edited by Foe89; Nov 12th, 2008 at 3:23 pm. Reason: code mistype
yep, you got it.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Dreaded IDE #1 ERROR info. (Storage)
- Simple Code needs fixing (PHP)
- help fixing my calculator in C (C)
- problems with referring to class variables (Java)
- Need help with fixing this type of error in my XP pro PC (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Help with classes and arrays
- Next Thread: Checking Whether a folder is a network share
Views: 379 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






