السلام عليكم ..
إخواني .. حبيت أطرح عليكم هالسؤال ..
أنا عرّفت class من نوع Student على هذا النحو :
#ifndef Student_H
#define Student_H
#include <string>
using std::string;
class Student
{
int id;
string name;
float gpa;
public:
Student(){id=0; name=""; gpa=0.0;}
void addStudent(int , string , float);
int getId(){return id;}
void printStudemt();
};
#endifوأيضا .. عرّفت Node و List على هذا النحو :
#ifndef List_H
#define List_H
#include "Student.h"
#include <iostream>
class Node
{
public:
Student data;
Node *next;
Node ( Student d , Node *n=0 ):data(d),next(n){}
};
class List
{
Node *head;
int count;
public:
// Constructor , Copy Constructot , Descrouctor
List (){head =0; count = 0;}
// Operation
void insert(const Student&);
void remove (Student &);
void print();
void printByName();
void printById(int);
};
#endifولكن .. عند إستخدامي لداله insert لإضافة student جديد ..
كتبتها بهذا الشكل :
void List::insert(const Student &s)
{
if (head == 0 )
{
head = new Node (s,head);
count++;
}
else
{
Node *p=head;
while (p != 0 && p->next->data.getId() < s.getId() )
p=p->next;
p->next=new Node (s,p->next);
count++;
}
}لكن .. الكومبايلر يظهر لي خطأ غريب !! في السطر هذا :
while (p != 0 && p->next->data.getId() < s.getId() )
يقول الخطأ :
--------------------Configuration: main - Win32 Debug-------------------- Compiling... main.cpp d:\unevirsty\csc113\lab\home work's\lab #6\ex1\list.cpp(18) : error C2662: 'getId' : cannot convert 'this' pointer from 'const class Student' to 'class Student &' Conversion loses qualifiers d:\unevirsty\csc113\lab\home work's\lab #6\ex1\list.cpp(18) : fatal error C1903: unable to recover from previous error(s); stopping compilation Error executing cl.exe. main.obj - 2 error(s), 0 warning(s)
رجاءا .. إخباري ما المشكلة !!!
:(