| | |
Question on my constructor
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi! I'm having a proble with constructors. I'm supposed to write a program that has a default constructor, but also one that takes parameters. The program I wrote below is desigend to allow teh setting of age of the person, but when I compile it, I get a message saying "no appropriate default constructor available". Any help greatly appreciated. Umm, and hints on how to correctly insert my posts so code shows up better would be great as well. Thanks again!
Thanks, Bill
Thanks, Bill
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::cin; using std::endl; class person { private: char first_name[30]; char last_name[30]; int itsAge; public: person(int initialAge); ~person(); void setting() { cout<<"Enter first_name "; cin>>first_name; cout<<"Enter last_name "; cin>>last_name; } void printing() { cout<<"The first_name "; cout<<first_name<<endl; cout<<"The last_name "; cout<<last_name<<endl; } }; //constructor of person person::person(int initialAge) // constructor { itsAge=initialAge; } person::~person() // destructor {} void main() { int pause; person p1; p1.setting(); p1.printing(); cin>> pause; }
Last edited by Ancient Dragon; Sep 8th, 2007 at 5:42 pm. Reason: corrected code tags
C++ Syntax (Toggle Plain Text)
public: person();
C++ Syntax (Toggle Plain Text)
person::person () // constructor { }
maybe add?
Last edited by iamthwee; Sep 8th, 2007 at 2:42 pm.
•
•
•
•
Does there have to be a default constructor?
Object obj; then Object has to have a default constructor, but if you do Object obj( arg ); then Object only has to have a constructor that takes a single argument.•
•
•
•
If I write a constructor that takes a parameter, am I obligated to write a seperate default constructor?
The truth does not change according to our ability to stomach it.
![]() |
Similar Threads
- Copy constructor in derived class (C)
- wierd gui/constructor problem (Java)
- Constructor Question? (C#)
- Newbie Constructor / Array question (C++)
- Taking address of constructors?? (C++)
- copy constructor problem (C++)
- How to call constructor for descendant of TObject ? (C++)
- Yet another initialise question (Java)
Other Threads in the C++ Forum
- Previous Thread: software
- Next Thread: Does anybody kno SU DOKU source code in C/C++?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






