0

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

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by vijayan121
1

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) ;
        // ...
    }
}
0

Thanks!!

Hey but what do these parts mean?:

#define HOMEPAGE_H_INCLUDED_

I mean what is the HOMEPAGE_H_INCLUDED_ defined as?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.