naveenath
naveenath

Reputation: 111

Is This How Association Work In C++?

class Staff{

public:
void createTeacher(TeacherRecord tr);

  tr.addTeacher();

}

class TeacherRecord{

public:
void addTeacher();
}

The logic to add the teacher will be in the TeacherRecord addTeacher() method. In this scenario a Staff uses the TeacherRecord object to add a new Teacher in to the list. Can this be called as Assocation Relationship?

Upvotes: 0

Views: 86

Answers (1)

Anony-mouse
Anony-mouse

Reputation: 2151

Theoretically no.According to the definition of association, the class Staff and the class Teacher should use each other.So the code should have been something like this:

#include <iostream>
using namespace std;
class TeacherRecord{

 public:
  void addTeacher(Staff school_staff);
};

class Staff{

 public:
  void createTeacher(TeacherRecord tr){
   tr.addTeacher(this);
  }

};
int main(){
return 0;
}

A few references which have helped me in understanding the concept are:

  1. This stack overflow question.
  2. This code project article.

Sorry for my long code.Hope this helps.

Upvotes: 1

Related Questions