C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,489 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,821 people online right now. Registration is fast and FREE... Join Now!




#include "header.h" please help

 

#include "header.h" please help, Including header file with class definition but nothing happens

excess3

2 Jul, 2009 - 03:31 PM
Post #1

New D.I.C Head
*

Joined: 10 Apr, 2009
Posts: 9


My Contributions
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.gif
IPB Image


here is the codes:
CLASSI.h
CODE
#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
CODE
#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

CODE
#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)



User is offlineProfile CardPM
+Quote Post


Oler1s

RE: #include "header.h" Please Help

2 Jul, 2009 - 03:39 PM
Post #2

D.I.C Addict
****

Joined: 4 Jun, 2009
Posts: 639



Thanked: 66 times
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Notorion

RE: #include "header.h" Please Help

2 Jul, 2009 - 04:07 PM
Post #3

D.I.C Regular
***

Joined: 17 Feb, 2009
Posts: 333



Thanked: 29 times
My Contributions
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)
CODE

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.
CODE

int Date::LeapYear ()

User is offlineProfile CardPM
+Quote Post

excess3

RE: #include "header.h" Please Help

3 Jul, 2009 - 03:21 AM
Post #4

New D.I.C Head
*

Joined: 10 Apr, 2009
Posts: 9


My Contributions
QUOTE(Notorion @ 2 Jul, 2009 - 04: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)
CODE

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.
CODE

int Date::LeapYear ()


omg good eye there man tnx tongue.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/8/09 04:17AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month