Hi, I have two classes in two separate .cpp files. I obtain a string using cin and then I need to use this string in a method in a separate class. If that makes sense..

class HomePage{
static void HsubmitChangeDutyRequests(string)
                          {
                          Duties::submitChangeDutyRequests(string);}
                          }
class Duties{
static void submitChangeDutyRequests(string);
}

This is basically what I have. I get the string from the HomePage class and then I use the method from the Duties class in the HomePage class using the string obtained. Again if that makes sense...
Sorry for the confusing questions..

Recommended Answers

All 3 Replies

For each class, you need to have a header file x.h and an implementation file x.cpp.
Include the header file in order to use the class.

For example:

//////////// duties.h /////////////////

#ifndef DUTIES_H_INCLUDED_
#define DUTIES_H_INCLUDED_

#include <string>

class Duties
{
    public: static void submitChangeDutyRequests( const string& ) ;
};

#endif // DUTIES_H_INCLUDED_
//////////// duties.cpp //////////////////

#include "duties.h"

void Duties::submitChangeDutyRequests( const string& requests )
{
   // ...
}
////////// homepage.h /////////////////////

#ifndef HOMEPAGE_H_INCLUDED_
#define HOMEPAGE_H_INCLUDED_

#include <string>

class HomePage
{
    public: static void HsubmitChangeDutyRequests( const string& ) ;
};

#endif // HOMEPAGE_H_INCLUDED_
//////////// homepage.cpp //////////////////

#include "homepage.h"
#include "duties.h"

void HomePage::HsubmitChangeDutyRequests( const string& requests )
{
   Duties::submitChangeDutyRequests( requests ) ;
}
////////////  main.cpp ////////////////////////

#include <iostream>
#include "homepage.h"

int main()
{
    // ...
    std::string request ;
    while( std::cout << "request? " && std::getline( std::cin, request ) )
    {
        // ...
        HomePage::HsubmitChangeDutyRequests(request) ;
        // ...
    }
}

Thanks!!

Hey but what do these parts mean?:

#define HOMEPAGE_H_INCLUDED_

I mean what is the HOMEPAGE_H_INCLUDED_ defined as?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.