| | |
Constructor troubles
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 10
Reputation:
Solved Threads: 0
Hi out there.
I can't get the constructors in my header files to work.
Here's a copy of my header file code:
And a copy of the function code:
I keep getting all the weird errors that you can find in my compile log. I'm running Dev C++ on Windows XP.
Thanx:cheesy:
Steven
I can't get the constructors in my header files to work.
Here's a copy of my header file code:
C++ Syntax (Toggle Plain Text)
#ifndef GUARD_PHEADER_H #define GUARD_PHEADER_H //The header file for the Person.cpp. //person_header.h #include <iostream> #include <string> //Person class declaration class Person { public: std::istream& read_surname(std::istream&); std::istream& read_name(std::istream&); std::istream& read_phone(std::istream&); std::istream& read_age(std::istream&); std::istream& read_weight(std::istream&); std::string& read_phone(std::string&); int& read_age(int&); double& read_weight(double&); std::string get_name() const { return name; } std::string get_surname() const { return surname; } std::string get_phone() const { return phone; } int get_age() const { return age; } double get_weight() const { return weight; } person(std::string&, std::string&, std::string&, int&, double&); Person(std::ifstream&); private: std::string surname; std::string name; std::string phone; int age; double weight; }; #endif
C++ Syntax (Toggle Plain Text)
//Constructor for Person Person::person(std::ifstream& in) : surname(0), name(0), phone(0), age(0), weight(0.0) { } //Constructor for Person Person::person(): surname(0), name(0), phone(0), age(0), weight(0.0) { }
Thanx:cheesy:
Steven
•
•
Join Date: Aug 2006
Posts: 10
Reputation:
Solved Threads: 0
Oh Yeah, and here's my compiler log...
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win" all
g++.exe -c person.cpp -o person.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
In file included from person.cpp:8:
person_header.h:26: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: prototype for `int Person::person(std::ifstream&)' does not match any in class `Person'
person_header.h:26: error: candidate is: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person(std::ifstream&)':
person.cpp:68: error: only constructors take base initializers
person.cpp: At global scope:
person.cpp:71: error: ISO C++ forbids declaration of `person' with no type
person.cpp:71: error: prototype for `int Person::person()' does not match any in class `Person'
person.cpp:68: error: candidates are: int Person::person(std::ifstream&)
person_header.h:26: error: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person()':
person.cpp:71: error: only constructors take base initializers
make.exe: *** [person.o] Error 1
Execution terminated
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win" all
g++.exe -c person.cpp -o person.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
In file included from person.cpp:8:
person_header.h:26: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: prototype for `int Person::person(std::ifstream&)' does not match any in class `Person'
person_header.h:26: error: candidate is: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person(std::ifstream&)':
person.cpp:68: error: only constructors take base initializers
person.cpp: At global scope:
person.cpp:71: error: ISO C++ forbids declaration of `person' with no type
person.cpp:71: error: prototype for `int Person::person()' does not match any in class `Person'
person.cpp:68: error: candidates are: int Person::person(std::ifstream&)
person_header.h:26: error: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person()':
person.cpp:71: error: only constructors take base initializers
make.exe: *** [person.o] Error 1
Execution terminated
Remeber that C++ is case-sensitive (uppercase and lowercase matter).
Last edited by Dave Sinkula; Sep 4th, 2006 at 11:02 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Copy constructor in derived class (C)
- copy constructor problem (C++)
- Constructor and Convertion operator are the same,how to avoid memory leak? (C++)
Other Threads in the C++ Forum
- Previous Thread: Multi-character support
- Next Thread: how to delete duplicate record...
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






