Well I thought it was working...
I seem to be having an error with my code that's assuming I've defined
functions twice. I have a class broken down in header files that seemed to work
but now it does not. here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// FRUITS.h
#include <iostream>
using namespace std;
#ifndef __NEW_FRUITS__
#define __NEW_FRUITS__
class NEWFRUITS
{
private:
unsigned short int size;
char name;
char color;
public:
// creation methods
void eatFruit();
void setName(char newName);
char getName();
void setColor(char newColor);
char getColor();
void setSize(unsigned short int newSize);
unsigned short int getSize();
// fruit methods
void APPLE();
void ORANGE();
void BANANA();
};
void NEWFRUITS::setSize(unsigned short int newSize)
{
size = newSize;
}
unsigned short int NEWFRUITS::getSize()
{
return size;
}
void NEWFRUITS::setName(char newName)
{
name = newName;
}
char NEWFRUITS::getName()
{
return name;
}
void NEWFRUITS::setColor(char newColor)
{
color = newColor;
}
char NEWFRUITS::getColor()
{
return color;
}
void NEWFRUITS::eatFruit()
{
cout << "You take a bit of the " << name << ".\n";
cout << "It are delicious.\n";
}
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// newFruitSet.cpp
#include <iostream>
#include "NEW_FRUITS.h"
using namespace std;
void NEWFRUITS::APPLE()
{
setSize(5);
}
void NEWFRUITS::ORANGE()
{
setSize(11);
}
void NEWFRUITS::BANANA()
{
setSize(87);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// newFruitsMain.cpp
#include <iostream>
#include "NEW_FRUITS.h"
using namespace std;
int main()
{
NEWFRUITS banana;
banana.BANANA();
cout << banana.getSize() << endl;
NEWFRUITS apple;
NEWFRUITS orange;
apple.APPLE();
orange.ORANGE();
cout << apple.getSize() << endl;
cout << orange.getSize() << endl;
system("PAUSE");
return 0;
}
|
with specific methods in the 'newFruitSet.cpp' file
for different sizes of fruit.
as said, it worked great earlier. These are the errors that popped up:
"multiple definition of 'NEWFRUITS::setSize(unsigned short)"
and it did this for all the functions I had declared.
If anyone can get this to work, that would be fantastic. Also if there's
any mistakes or common beginner hangups with the way I coded, please let me know.
Thanks!
-- Mark