#include "header.h" please help

Including header file with class definition but nothing happens

Page 1 of 1

3 Replies - 349 Views - Last Post: 03 July 2009 - 04:21 AM Rate Topic: -----

#1 excess3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 10-April 09

#include "header.h" please help

Post icon  Posted 02 July 2009 - 04:31 PM

Hello guys , i just started to learn classes and the code i made looks ok for me, for the CLASSI.h has class definition
and the CLASSI.cpp basicly the functions that the class contains and main.cpp main function that creating object
with this class and uses it but when i compile i got error (from which i understand the CLASSI.cpp dont see class in header file) what can i do ? :blink:
Posted Image


here is the codes:
CLASSI.h
#ifndef _CLASSI_H_
#define _CLASSI_H_
#include <iostream> 
using namespace std;
#include <conio.h>
#include <stdio.h>
class Date
{
private:
	int day,month,year;
public:
	Date(int d,int m,int y){day=d;month=m;year=y;}
	int LeapYear ();	
	int DaysInMonth ();
	int Day(){return day;}

void PrintDate ();		   
void IncreaseDate ();				   
void PrintLeap ();

};

#endif



CLASSI.cpp
#include "CLASSI.h"





int Data::LeapYear ()
{
	if (year%4==0 || year%400==0)
	{
		return 1;
	}
	else {return 0;}
}

int Data::DaysInMonth ()
{
	int i;
	int m=1;
	for(i=0;i<month;i++)
	{
		if(m==8){m++;}
		m++ ;

	}
	if(m==2 && LeapYear()==1){return 29;}
	else {if(m==2){return 28;}
	else{return (30+(m%2));}
	}

}



void Data::PrintDate ()
{
	cout<<"Date: "<<day<<"/"<<month<<"/"<<year<<endl;
}
void Data::IncreaseDate ()
{
	if(day==DaysInMonth()){day=1;month++;if(month==13){month=1;}}else{day++;}
}
void Data::PrintLeap ()
{
	if(LeapYear ()) {cout<<"- This year is a 'Leap Year'"<<<endl; }
}


Main.cpp

#include "CLASSI.h"

int  main ( )
{	
	Date  newYearsDay (1,1,2000);
	newYearsDay.PrintDate ();		  
	newYearsDay.IncreaseDate ();					 
	newYearsDay.PrintDate ();	
	newYearsDay.PrintLeap ();		  

	Date  d (30,3,2006);
	d.IncreaseDate ();
	d.PrintDate ();
	d.PrintLeap ();

	for (Date dd(25,2,1992);  dd.Day()<3 || dd.Day()>10;  dd.IncreaseDate())
		dd.PrintDate ();
	return 0;
}



Error list

Build Log


Build started: Project: HW5_1, Configuration: Debug|Win32

Command Lines


Creating temporary file "c:\Documents and Settings\Andrey\My Documents\Visual Studio 2008\Projects\HW5_1\HW5_1\Debug\RSP00007C20721844.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\CLASSI.cpp"
]
Creating command line "cl.exe @"c:\Documents and Settings\Andrey\My Documents\Visual Studio 2008\Projects\HW5_1\HW5_1\Debug\RSP00007C20721844.rsp" /nologo /errorReport:prompt"

Output Window


Compiling...
CLASSI.cpp
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(7) : error C2653: 'Data' : is not a class or namespace name
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(9) : error C2065: 'year' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(9) : error C2065: 'year' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(16) : error C2653: 'Data' : is not a class or namespace name
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(20) : error C2065: 'month' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(35) : error C2653: 'Data' : is not a class or namespace name
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(37) : error C2065: 'day' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(37) : error C2065: 'month' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(37) : error C2065: 'year' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(39) : error C2653: 'Data' : is not a class or namespace name
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'day' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'day' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'month' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'month' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'month' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(41) : error C2065: 'day' : undeclared identifier
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(43) : error C2653: 'Data' : is not a class or namespace name
c:\documents and settings\andrey\my documents\visual studio 2008\projects\hw5_1\hw5_1\classi.cpp(45) : error C2059: syntax error : '<'

Results


Build log was saved at "file://c:\Documents and Settings\Andrey\My Documents\Visual Studio 2008\Projects\HW5_1\HW5_1\Debug\BuildLog.htm"
HW5_1 - 18 error(s), 0 warning(s)

Is This A Good Question/Topic? 0
  • +

Replies To: #include "header.h" please help

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: #include "header.h" please help

Posted 02 July 2009 - 04:39 PM

You typed Data as in Data::LeapYear, but you obviously meant Date.

How I found this error: the compiler error message said so. The first error is: classi.cpp(7) : error C2653: 'Data' : is not a class or namespace name. So I looked at line 7 (that's what the number means) in classi.cpp. I saw that you had Data::something. Clearly, the complaint was about Data. It said it wasn't a class name, but here you were using it as one. So I looked in the header file to find Data.

I found Date instead. So I deduced that you meant to type Date and not Data.

Moral: Read the error messages, because they tell you what to look for.

What you should do in the future: Read the error messages. If you don't understand the first message, ask here about how to understand it.
Was This Post Helpful? 1
  • +
  • -

#3 Notorion  Icon User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

Re: #include "header.h" please help

Posted 02 July 2009 - 05:07 PM

The problem is with you .cpp file, because the compiler doesn't know who these functions belong to essentially. You need to tell it they are from the date class.


For example you have this function below in your ccp files
(we will just use one function for an example, but it applies to all of them)
int Data::LeapYear ()




The code should be from the class Date, not Data.
So change your previous function to use the scope of the Date class.
int Date::LeapYear ()


Was This Post Helpful? 1
  • +
  • -

#4 excess3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 10-April 09

Re: #include "header.h" please help

Posted 03 July 2009 - 04:21 AM

View PostNotorion, on 2 Jul, 2009 - 04:07 PM, said:

The problem is with you .cpp file, because the compiler doesn't know who these functions belong to essentially. You need to tell it they are from the date class.


For example you have this function below in your ccp files
(we will just use one function for an example, but it applies to all of them)
int Data::LeapYear ()




The code should be from the class Date, not Data.
So change your previous function to use the scope of the Date class.
int Date::LeapYear ()


omg good eye there man tnx :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1