473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot create an object from a class i created. Help!

Ok, first off I am learning C++ for the first time. I know Java very
well, but a new class of mine requires C++. So bare with me please.

I have 2 classes, Birthday.cpp and BirthdayParadox .cpp

Birthday is a class and Birthday paradox is mainly the driver for it. I
am trying to create an object of Birthday in BirthdayParadox and it is
not working.
I get the error: "'Birthday' undeclared (first use this function)"

any idea?

Birthday.cpp
---------------------------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

// #include any header files you need here
class Birthday
{
public:

int bDay;

// standard constructor
// default to January 1st if user provides invalid data
Birthday::Birth day(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy 365 )
{
bDay = 1;
}
else
bDay = doy;
}

// Default constructor which generates a random birthday
// between January 1st and December 31. We assume only non-leap years

Birthday::Birth day()
{

bDay = setDay();

}

// Set birthday randomly
int Birthday::setDa y()
{
srand((unsigned )time(0));
int random_integer = rand();

for(int index=0; index<1; index++)
{
random_integer = (rand()%365)+1;
}

return random_integer;
}

// Test for birthday equality
bool Birthday::opera tor==( const Birthday &b)const
{

// fill in your code here
return true;

}

/*// print birthday information
std::ostream& operator<<(std: :ostream& out, const Birthday &b)
{

// fill in your code here
cout>"test";
} */
};

BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

// #include any other necessary header files here
// also the required "using" statements

void testBirthdayPar adox()
{ // Birthday Paradox test function

Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;

// fill in your code here

}

int main()
{
char c;

//testBirthdayPar adox();

cin >c; // to force the DOS screen to stay until you press any
character

return EXIT_SUCCESS; // successful execution
}

Sep 11 '06 #1
5 2420
I have 2 classes, Birthday.cpp and BirthdayParadox .cpp
I do not see two classes here.
There is only one class in Birthday.cpp.
You are getting this error because the BirthDay class is not available
for the BirthDayParadox .cpp compilation unit. (Every cpp file is
converted into a .obj as a separate compilation unit.) So you should
include the file declaring the Birthday class in this file.

I'll suggest you should have two separate files,

Birthday.h file as

#ifndef __BIRTHDAY__
#defeine __BIRTHDAY__
//Incldue whatever is required

class BirthDay
{
public:
// Declare Funtions and members
};
#endif //__BIRTHDAY__
------------------------------------------------------
Second file. BirthDay.cpp
#include "BirthDay.h "
// Include other files required

//Implement the functions here.
Birthday::Birth day(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy 365 )
{
bDay = 1;
}
else
bDay = doy;
}
-----------------------------------------------

The paradox file will ermain the same as it is with addition of
following

#include "BirthDay.h "
regards
Amir Kamerkar

Sep 11 '06 #2

Willson wrote:
Ok, first off I am learning C++ for the first time. I know Java very
well, but a new class of mine requires C++. So bare with me please.

I have 2 classes, Birthday.cpp and BirthdayParadox .cpp

Birthday is a class and Birthday paradox is mainly the driver for it. I
am trying to create an object of Birthday in BirthdayParadox and it is
not working.
I get the error: "'Birthday' undeclared (first use this function)"

any idea?

Birthday.cpp
---------------------------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

// #include any header files you need here
class Birthday
{
public:

int bDay;

// standard constructor
// default to January 1st if user provides invalid data
Birthday::Birth day(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy 365 )
{
bDay = 1;
}
else
bDay = doy;
}

// Default constructor which generates a random birthday
// between January 1st and December 31. We assume only non-leap years

Birthday::Birth day()
{

bDay = setDay();

}

// Set birthday randomly
int Birthday::setDa y()
{
srand((unsigned )time(0));
int random_integer = rand();

for(int index=0; index<1; index++)
{
random_integer = (rand()%365)+1;
}

return random_integer;
}

// Test for birthday equality
bool Birthday::opera tor==( const Birthday &b)const
{

// fill in your code here
return true;

}

/*// print birthday information
std::ostream& operator<<(std: :ostream& out, const Birthday &b)
{

// fill in your code here
cout>"test";
} */
};

BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

// #include any other necessary header files here
// also the required "using" statements

void testBirthdayPar adox()
{ // Birthday Paradox test function

Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;

// fill in your code here

}

int main()
{
char c;

//testBirthdayPar adox();

cin >c; // to force the DOS screen to stay until you press any
character

return EXIT_SUCCESS; // successful execution
}
please add header file.
like this:
BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
//add header file
#include "Birthday.c pp"
>
using namespace std;

// #include any other necessary header files here
// also the required "using" statements

void testBirthdayPar adox()
{ // Birthday Paradox test function

Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;

// fill in your code here

}

int main()
{
char c;

//testBirthdayPar adox();

cin >c; // to force the DOS screen to stay until you press any
character

return EXIT_SUCCESS; // successful execution
}
Sep 11 '06 #3
don't you need to include a header file of birthday in your
BirthdayParadox ??
I'm still a newbie so i might be wrong...hope this helps you.

Willson wrote:
Ok, first off I am learning C++ for the first time. I know Java very
well, but a new class of mine requires C++. So bare with me please.

I have 2 classes, Birthday.cpp and BirthdayParadox .cpp

Birthday is a class and Birthday paradox is mainly the driver for it. I
am trying to create an object of Birthday in BirthdayParadox and it is
not working.
I get the error: "'Birthday' undeclared (first use this function)"

any idea?

Birthday.cpp
---------------------------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

// #include any header files you need here
class Birthday
{
public:

int bDay;

// standard constructor
// default to January 1st if user provides invalid data
Birthday::Birth day(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy 365 )
{
bDay = 1;
}
else
bDay = doy;
}

// Default constructor which generates a random birthday
// between January 1st and December 31. We assume only non-leap years

Birthday::Birth day()
{

bDay = setDay();

}

// Set birthday randomly
int Birthday::setDa y()
{
srand((unsigned )time(0));
int random_integer = rand();

for(int index=0; index<1; index++)
{
random_integer = (rand()%365)+1;
}

return random_integer;
}

// Test for birthday equality
bool Birthday::opera tor==( const Birthday &b)const
{

// fill in your code here
return true;

}

/*// print birthday information
std::ostream& operator<<(std: :ostream& out, const Birthday &b)
{

// fill in your code here
cout>"test";
} */
};

BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

// #include any other necessary header files here
// also the required "using" statements

void testBirthdayPar adox()
{ // Birthday Paradox test function

Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;

// fill in your code here

}

int main()
{
char c;

//testBirthdayPar adox();

cin >c; // to force the DOS screen to stay until you press any
character

return EXIT_SUCCESS; // successful execution
}
Sep 11 '06 #4
thanks for the replies, I will have to research what header files are
and do, but hopefully that will solve the problem. I didnt know C++
needed a header file

Sep 11 '06 #5
In article <11************ **********@p79g 2000cwp.googleg roups.com>,
"Willson" <ha*****@gmail. comwrote:
#include <iostream>
#include <iomanip>
#include <cstdlib>
Did you forget to include "Birthday.h "?
>
using namespace std;
Don't include header files here, include them all before the using
statements.
// #include any other necessary header files here
// also the required "using" statements

void testBirthdayPar adox()
{ // Birthday Paradox test function

Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;

// fill in your code here

}

int main()
{
char c;

//testBirthdayPar adox();

cin >c; // to force the DOS screen to stay until you press any
character

return EXIT_SUCCESS; // successful execution
}
--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
7
7844
by: Holger Grund | last post by:
What's special about System::String? For instance, why can't one write a function like using System::String; void foo( const String% ); or what's wrong with: int main() {
0
1347
by: Andrew | last post by:
Hi, When I click on File > New > New Project on the VS.NET 2003 menu, I get the normal window asking me what type of project I would like to create. After choosing the ASP.NET Web Application, I click on "OK". I get an error message stating: "Microsoft Development Environment Object with program ID VsWizard.VsWizardEngine.7.1 cannot be created." There is an OK and Help button, when I click on Help I get a Help window
7
6787
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al = LoadOracleData(sql) '____Do amazing things
7
1924
by: Christian Christmann | last post by:
Hi, in my source code I've included a library I've not written and source code is available. In a function, I've generate an object of that library class dynamically with "new" and at the function's end I want to freed memory for that object with "delete". However, doing that seem to be not allowed since I get the compiler error:
2
6592
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} I then determine what object I should call the Persist method on using a switch statement (not very OO). switch (otype)
1
5382
by: Allan Ebdrup | last post by:
I get the error: "Cannot create an object of type 'CustomWizard' from its string representation 'CustomWizard1' for the CustomWizard Property." when I view my custom server web control in design view. Everything runs fine when I run the page, it's only design view that gives the error. My custom server web control is inherited form the wizard control. In OnInit I add a Child to the wizard, witch is also a custom server web
3
2292
by: gasfusion | last post by:
Hey guys. I'm building an object collection which will be a part of a Data Access Layer i am currently working on. However, i am having some issues iterating through a collection. This is what i've done so far 1 - Create 'user' class which maps to the MySQL table. The class has basic setters and getters to set/get each field value. 2 - Created a collection class with simple add/remove/get methods. 3 - Created user collection class which...
2
6660
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
4
1877
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.