944,114 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3733
  • C++ RSS
Sep 4th, 2006
1

Constructor troubles

Expand Post »
Hi out there.

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)
  1. #ifndef GUARD_PHEADER_H
  2. #define GUARD_PHEADER_H
  3.  
  4. //The header file for the Person.cpp.
  5. //person_header.h
  6.  
  7. #include <iostream>
  8. #include <string>
  9.  
  10. //Person class declaration
  11. class Person {
  12. public:
  13. std::istream& read_surname(std::istream&);
  14. std::istream& read_name(std::istream&);
  15. std::istream& read_phone(std::istream&);
  16. std::istream& read_age(std::istream&);
  17. std::istream& read_weight(std::istream&);
  18. std::string& read_phone(std::string&);
  19. int& read_age(int&);
  20. double& read_weight(double&);
  21. std::string get_name() const { return name; }
  22. std::string get_surname() const { return surname; }
  23. std::string get_phone() const { return phone; }
  24. int get_age() const { return age; }
  25. double get_weight() const { return weight; }
  26. person(std::string&, std::string&, std::string&, int&, double&);
  27. Person(std::ifstream&);
  28. private:
  29. std::string surname;
  30. std::string name;
  31. std::string phone;
  32. int age;
  33. double weight;
  34. };
  35. #endif
And a copy of the function code:
C++ Syntax (Toggle Plain Text)
  1. //Constructor for Person
  2.  
  3. Person::person(std::ifstream& in) : surname(0), name(0), phone(0), age(0), weight(0.0) { }
  4.  
  5. //Constructor for Person
  6. Person::person(): surname(0), name(0), phone(0), age(0), weight(0.0) { }
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
Similar Threads
Reputation Points: 19
Solved Threads: 0
Newbie Poster
V1RuZ is offline Offline
10 posts
since Aug 2006
Sep 4th, 2006
1

Re: Constructor troubles

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
Reputation Points: 19
Solved Threads: 0
Newbie Poster
V1RuZ is offline Offline
10 posts
since Aug 2006
Sep 4th, 2006
1

Re: Constructor troubles

Oh yeah, the error on line 26 occurs in the header and 68 and 71 occur in the definition of the functions
Reputation Points: 19
Solved Threads: 0
Newbie Poster
V1RuZ is offline Offline
10 posts
since Aug 2006
Sep 4th, 2006
1

Re: Constructor troubles

Remeber that C++ is case-sensitive (uppercase and lowercase matter).
Last edited by Dave Sinkula; Sep 4th, 2006 at 11:02 pm.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Multi-character support
Next Thread in C++ Forum Timeline: how to delete duplicate record...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC