#include"Ccommittee.h"
Ccommittee::Ccommittee()
{
Admin=2012;
}
int Ccommittee::Admin = 2012;
void Ccommittee::Assignedproposal(Proposal &newProposal ,Reviewer &newreviewer)
{
proposal = &newProposal;
reviewer = &newreviewer;
}
void Ccommittee::Creatreviewer(User &newuser)
{
user=&newuser;
Reviewer R(newuser);
cout<<" creat R in function\n"<<R.R_ID<<"inside cpp"<<endl;//this work and it create the new object ,
// but my problem that i cant get the object in main
//, so i need the function to return object , how can i try to change void into Reviewer but it didnt work , i think there is special way
//, which i search about it but i didnt find .
}
Just create a member function of com into which you would dynamically allocate rev objects on heap (using new).
Keep track of the pointer returned since you should delete them afterward (when rev goes out of scope or com or rev needed to be deleted etc). You can do this by adding them to a vector for example.
Make sure you delete the object allocated before destroying com (into it's destructor delete first all rev objects)
actually i have another class , i can create new object , and it already work , but the problem that its destructed and i couldnt get it in the main program .
this is the class for the object which i create
rev:
User U7(50,"dr.ayman","malaysia");
C.Creatreviewer(U7);
cout<<C.reviewer->R_ID<<" in main class .cpp \n";
the result as below:
203 inside rev.cpp
create R in function
203 inside com cpp
the last cout statement in main class cant be execute , i think coz the object destructed , how can i keep this object until it reach the main class , then i will push it in vector .
"Ccommittee::reviewer" should hold a copy of the Reviewer object that was created in the member function "Creatreviewer(...)" instead of a reference to it.
i deleted creatviewer function , and i use the object member directly from the main menu as below": C.reviewer= new Reviewer(U7);
it works correctly now .
thank u cplupsplus forum members .
User U7(50,"dr.ayman","malaysia");
C.Creatreviewer(U7); //as a side efect C.user will be changed. Nothing more
cout<<C.reviewer->R_ID<<" in main class .cpp \n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Reviewer
{
public:
staticint nextID;
int R_ID;
User* user;
Reviewer* reviewer; //please explain this link
Proposal* proposal;
public:
Reviewer();
Reviewer( User&); //there is no initialized here
Reviewer(Reviewer&,Proposal&);
void acceptReview(Proposal&);
void rejectReview(Proposal&);
};
You have variables unitialized (acording to which constructor you use).