954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with C++ functions

hey,
it's me again, i need help with creating a header file for some functions so that i can use the functions in some other programs....
for example a header file that will include the function prototypes that i can access... I need the syntax for it.....:)

addicted
Junior Poster in Training
57 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
// yourheader.h
#ifndef _a_yourheader_included_
#define _yourheader_h_included_
class A
{
   B m_b;
   C *m_c;
   D *m_d;
  
public:
  void SetC(C *c);
  C *GetC() const;
  
  void ModifyD(D *d);
};
#endif

/************************************/

// yourcpp.cpp
void A::SetC(C* c)
{
  m_c = c;
}

C* A::GetC() const
{
  return m_c;
}

void A::ModifyD(D* d)
{
  d->SetX(0);
  d->SetY(0);
  m_d = d;
}
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
// yourheader.h
#ifndef _a_yourheader_included_
#define _yourheader_h_included_
class A
{
   B m_b;
   C *m_c;
   D *m_d;
 
public:
  void SetC(C *c);
  C *GetC() const;
 
  void ModifyD(D *d);
};
#endif
 
/************************************/
 
// yourcpp.cpp
void A::SetC(C* c)
{
  m_c = c;
}
 
C* A::GetC() const
{
  return m_c;
}
 
void A::ModifyD(D* d)
{
  d->SetX(0);
  d->SetY(0);
  m_d = d;
}



thanks,
but i dont think this code is meant for me.... what i expected was an deader file that contains a set of function prototypes... like a class' interface.... all i need is the declaration syntax for example

(declaration)header file name{
function 1;
function 2;
function 3;
}


so that when i want to use them i can just use the code

#include "header file name"


do you understand?

the syntax i will use:)

addicted
Junior Poster in Training
57 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
// header_file.h
#ifndef header_file
#define header_file

void function1();
void function2();

#endif

//////

// function_file.cpp
#include "header_file.h"

void function1() {

   // ....
}

//////

// main.cpp

#include "header_file.h"

int main() {

    function1();
    return 0;
}
John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You