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 8610227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:04:44+00:00 2026-06-12T04:04:44+00:00

I have two classes, one and two , each having a friend member function

  • 0

I have two classes, one and two, each having a friend member function with an pointer to the other. The first header file is as per below:

#ifndef FIRSTCLASS_H
#define FIRSTCLASS_H

class two;

class one {

private:
int one_data;

public:
friend void second_data (two *);
};

#endif

The second header file looks like this:

#ifndef SECONDCLASS_H
#define SECONDCLASS_H

class one;

class two {

private:
int two_data;

public:
friend void first_data (one *);
};

#endif

The actual functions are in a third .cpp file. I wrote the functions with appropriate class qualifier, it gives an compilation error. I am using g++. The functions are as follows:

#include "firstclass.h"
#include "secondclass.h"

void two::first_data (one * class1) {

}

 void one::second_data (two * class2) {

}

The errors are as followa:

 error:no ‘void two::first_data (one*)’ member function declared in class ‘two’ 
 error: no ‘void one::second_data(two*)’ member function declared in class ‘one’

When I drop the class qualifier before the function name, the code compiles. The modified functions are as follows:

 void first_data(one * class1) {

 }

 void second_data(two * class2) {

 }

I am new to c++ and I am not sure if I am doing anything wrong in the first case. Please enlighten me.

  • 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-06-12T04:04:46+00:00Added an answer on June 12, 2026 at 4:04 am

    What you declare is freestanding functions as friends of your classes.
    They are not really members of any class.

    friend void first_data (one *); 
    

    declares a freestanding function first_data as friend of your class, it does not mean first_data is a member function of your class. Hence when you define the function in cpp file the compiler complains that the function was never declared.

    Also,

    void two::first_data (one * class1){}
    
    Returntype ClassName ScopeResolution FunctionSignature
    

    two:: tells compiler the functions belongs to this particular class, it is not namespace specification, it is class qualification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, one is the parent of the other. They both need
I am having dependency troubles. I have two classes: Graphic and Image . Each
I have two classes, one has a lot of properties and the other has
I'm new to rails and having issues with scope. I have two classes, Post
there are two dataobject classes A and B having one-to-many relationship. I want to
I have a script which contains two classes. (I'm obviously deleting a lot of
How can I compact the jQuery Code Below? //FIRST CODE jQuery('.expand-two').click(function(){ jQuery('.content-two').slideToggle('fast'); }); jQuery('.expand-two').toggle(function()
We currently have quite a few classes in a project, and each of those
Ok so I have two classes in which they are not really associated with
I am working on a business problem in C#.NET. I have two classes, named

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.