Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:32:22+00:00 2026-05-22T15:32:22+00:00

I will have two files. One header.h file and second one is main.c file.

  • 0

I will have two files. One header.h file and second one is main.c file.

Now, how to make a header.h file with methods written in C (such as print test etc), then in main.c file, how can I access them with operators such as :: or ->

@file: main.c

#include "header.h"; // sorry i made mistake before

int main()
    {
      A::myStaticFunction();

      // OR

      A->myInstanceFunction();

      return 0;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:32:23+00:00Added an answer on May 22, 2026 at 3:32 pm

    I would like to do it completely in C.
    (from @Sonia’s comment on @Als’ answer)

    Not completely possible. What you got there is C++ code, it can’t be emulated in C in exactly that way.

    In C, a struct can’t have functions, only function pointer and also can’t have any static members at all. So, no :: for you in that regard. Your other example, on @David’s answer, is most likely an enum:

    typedef enum _H323Connection{
      AnswerCallNow,
      AnswerCallLater,
      IgnoreCall,
      /* examples */
    }H323Connection;
    

    Now, to get one of those values inside the enum you can just use the name (IgnoreCall) or qualify it with the enum’s name (H323Connection::IgnoreCall).

    The -> operator, however, is totally possible.

    typedef struct _sA{
      // function pointer
      void (*AnswerCall)(struct _sA*, H323Connection);
      // variables...
    }sA;
    
    void sA_AnswerCall(sA* self, H323Connection callmode){
      // do something with self
      switch(callmode){
        case AnswerCallNow: /* ... */ break;
        case AnswerCallLater: /* ... */ break;
        case IgnoreCall: /* ... */ break;
      }
    }
    
    int main(){
      sA* pA = (sA*)malloc(sizeof(sA));
    
      // assign function pointer;
      pA->AnswerCall = sA_AnswerCall;
      // call it and pass "this" (the object the function operates on)
      pA->AnswerCall(pA, H323Connection::AnswerCallNow);
      // in C++ ---- ^^ would be the "this" pointer and 
      // would be passed secretly by the compiler
    
      free(pA);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have two files. Let's call the file controlling a second one:
I have two files in my src/main/resources and I want one file's body to
I have a really simple class with two methods; One that will be called
I have these two header files and one produces an error if I don't
I have two files with slight differences. A normal diff will show me the
I have two processes one will query other for data.There will be huge amount
i have two files one called stats.js one called storage.html in stats.js in contains
For example, if I have two files: file1: This is file 1 and file2:
I have two excel files. First excel file contains the Person Name and Total
I am using Windows, and I have two monitors. Some applications will always start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.