color.h
//color.h
//Color class definition
#ifndef COLOR_H
#define COLOR_H
class color
{
public:
enum col {black, blue, green, cyan, red, magenta, brown, lightgray, nocolor};
color();
//Member functions
//read color in
void readColor ();
//write color out
void writeColor ()const;
//accessor functions
void setColor(col);
int getColor() const;
private:
//data members
enum {capacity = 255};
col cColor;
char contents[capacity];
int length;
};
#endif
color.cpp
#include "color.h"
#include <iostream>
#include <string>
using namespace std;
// Member Functions...
// constructor
color::color()
{
cColor = nocolor;
}
// Set color
void color::setColor(col c)
{
cColor = c;
}
void color::readColor()
{
string c;
cout << "Please enter a color from the following list: black, blue, green, cyan, red, magenta, brown, lightgray, or nocolor." << endl;
cin >> c;
}
// Display attributes
void color::writeColor() const
{
cout << "color is " << cColor << "or # " << int(cColor) << endl;
}
// accessor functions
int color::getColor() const
{
return cColor;
}
colorTest.cpp
#include "color.h"
#include <iostream>
using namespace std;
int main()
{
color myColor();
// Set circle attributes.
myColor.readColor();
myColor.setColor(color::magenta);
// Display the circle attributes.
myColor.writeColor;
return 0;
}
The first two compile fine, though I'm not sure they're correct other than syntax. I keep getting these errors when trying to compile the test:
Quote
colorTest.cpp: In function `int main()':
colorTest.cpp:14: error: request for member `readColor' in `myColor', which is of non-class type `color ()()'
colorTest.cpp:15: error: request for member `setColor' in `myColor', which is of non-class type `color ()()'
colorTest.cpp:18: error: request for member `writeColor' in `myColor', which is of non-class type `color ()()'
colorTest.cpp:14: error: request for member `readColor' in `myColor', which is of non-class type `color ()()'
colorTest.cpp:15: error: request for member `setColor' in `myColor', which is of non-class type `color ()()'
colorTest.cpp:18: error: request for member `writeColor' in `myColor', which is of non-class type `color ()()'

New Topic/Question
Reply



MultiQuote








|