• Advertisement
Sign in to follow this  

Class Help!

This topic is 2020 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my header file Pen.h

#ifndef PEN_H_INCLUDED
#define PEN_H_INCLUDED
using namespace std;
enum Color
{
blue,
red,
black,
clear
};
enum PenStyle
{
ballpoint,
felt_tip,
fountain_pen
};
class Pen
{
public:
Color InkColor;
Color ShellColor;
Color CapColor;
PenStyle Style;
float Length;
string Brand;
int InkLevelPercent;
void write_on_paper(string words)
{
if (InkLevelPercent <= 0)
{
cout << "Oops! Out of ink!" << endl;
}
else
{
cout << words << endl;
InkLevelPercent = InkLevelPercent - words.length();
}
}
void break_in_half()
{
InkLevelPercent = InkLevelPercent / 2;
Length = Length / 2.0;
}
void run_out_of_ink()
{
InkLevelPercent = 0;
}
};
#endif // PEN_H_INCLUDED


my source file Pen.cpp


// Pen.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "Pen.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
Pen FavoritePen;
FavoritePen.InkColor = blue;
FavoritePen.ShellColor = clear;
FavoritePen.CapColor = black;
FavoritePen.Style = ballpoint;
FavoritePen.Length = 6.0;
FavoritePen.Brand = "Pilot";
FavoritePen.InkLevelPercent = 90;
Pen WorstPen;
WorstPen.InkColor = blue;
WorstPen.ShellColor = red;
WorstPen.CapColor = black;
WorstPen.Style = felt_tip;
WorstPen.Length = 3.5;
WorstPen.Brand = "Acme Special";
WorstPen.InkLevelPercent = 100;
cout << "This is my favorite pen" << endl;
cout << "Color: " << FavoritePen.InkColor << endl;
cout << "Brand: " << FavoritePen.Brand << endl;
cout << "Ink Level: " << FavoritePen.InkLevelPercent << "%" << endl;
system("pause");
return 0;
}


along with the error code...

1>------ Build started: Project: Pen, Configuration: Debug Win32 ------
1> Pen.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(18): error C2065: 'Pen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(18): error C2146: syntax error : missing ';' before identifier 'FavoritePen'
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(18): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(19): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(19): error C2228: left of '.InkColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(19): error C2065: 'blue' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(20): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(20): error C2228: left of '.ShellColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(20): error C2065: 'clear' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(21): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(21): error C2228: left of '.CapColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(21): error C2065: 'black' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(22): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(22): error C2228: left of '.Style' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(22): error C2065: 'ballpoint' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(23): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(23): error C2228: left of '.Length' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(24): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(24): error C2228: left of '.Brand' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(25): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(25): error C2228: left of '.InkLevelPercent' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(26): error C2065: 'Pen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(26): error C2146: syntax error : missing ';' before identifier 'WorstPen'
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(26): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(27): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(27): error C2228: left of '.InkColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(27): error C2065: 'blue' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(28): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(28): error C2228: left of '.ShellColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(28): error C2065: 'red' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(29): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(29): error C2228: left of '.CapColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(29): error C2065: 'black' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(30): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(30): error C2228: left of '.Style' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(30): error C2065: 'felt_tip' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(31): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(31): error C2228: left of '.Length' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(32): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(32): error C2228: left of '.Brand' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(33): error C2065: 'WorstPen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(33): error C2228: left of '.InkLevelPercent' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(35): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(35): error C2228: left of '.InkColor' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(36): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(36): error C2228: left of '.Brand' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(37): error C2065: 'FavoritePen' : undeclared identifier
1>c:\users\jonbecher\documents\visual studio 2012\projects\pen\pen\pen.cpp(37): error C2228: left of '.InkLevelPercent' must have class/struct/union
1> type is ''unknown-type''
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I don't understand why these are supposedly undeclared identifiers yet they are in the .h file.
Any help would be much appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Add
#include <string>
#include <iostream>

To the top of pen.h.

Share this post


Link to post
Share on other sites
SOLVED

IDE error in compiling process. Edited by JonBMN

Share this post


Link to post
Share on other sites
First off, always put that all code inaide the include guard , so move the #include below the #define.

Second, that code compiles fine for me, using the same compiler, so my only guess is your project is somehow misconfigured. I am on my phone now, but if you want i can zip up the working version, although the only changes are the #includes, plus I obviously made the project from scratch.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement