I'm doing a homework assignment about constructors and this is really bothering me. I keep getting the error "constructors are not allowed a return type".
I HAVE put a semicolon after the class declaration.
I'll post my code here.
// Joseph Yong
// CSC2430
// Homework_6
//Header File
/*--------------------------------------------------------------------------*/
#include <iostream>
#include <string>
using namespace std;
class Bible
{
public:
//Constructors
Bible();
Bible(string nam, int chapt, int vers, string testa, string txt);
//Mutators
void setName(string nam);
void setChapter(int chapt);
void setVerse(int vers);
void setTestament(string testa);
void setText(string txt);
void setSetup1(string nam, int chapt, int vers, string testa);
void setInput();
//Accessors
string getName();
int getChapter();
int getVerse();
string getTestament();
string getText();
//Output
void write1();
void write2();
private:
string name, testament, text;
int chapter, verse;
};
// Joseph Yong
// CSC2430
// Homework 6
//Implementation File
/*----------------------------------------------------------------*/
#include <iostream>
#include <string>
using namespace std;
#include "Header1.h"
//Constructors
Bible::Bible()
: chapter(0), verse(0)
{
}
Bible::Bible(string nam, int chapt, int vers, string testa, string txt) //Initialize to any size
//Mutators
void Bible::setName(string nam)
{
name = nam; //Change the string value of name
}
void Bible::setChapter(int chapt)
{
chapter = chapt; //Change the int value of chapter
}
void Bible::setVerse(int vers)
{
verse = vers; //Change the int value of verse
}
void Bible::setTestament(string testa)
{
testament = testa; //Change the string value of testament
}
void Bible::setText(string txt)
{
text = txt; //Change the string value of text
}
void Bible::setSetup1(string nam, int chapt, int vers, string testa)
{
name = nam;
chapter = chapt; //Changes all data members
verse = vers;
testament = testa;
}
string Bible::setInput(string ver)
{
cout << "Enter in the verse text: ";
cin >> ver; //Changes the string value of input
verse = ver;
}
//Accessors
int Bible::getName()
{
return name;
}
int Bible::getChapter()
{
return chapter;
}
int Bible::getVerse()
{
return verse;
}
string Bible::getTestament()
{
return testament;
}
int Bible::getText()
{
return text;
}
//Output
void Bible::write1()
{
cout << bib.getName << " " << bib.getChapter << ":" << bib.getVerse << " " << bib.getTestament << endl;
cout << bib.getText;
}
Any help would be greatly appreciated!
Also, this code is yet to be finished. So in regards with "bib.getname" I understand that will bring me an error as I have yet to code main.cpp ;).
Thanks dani!
**This is my first post as I JUST joined daniweb ^^