hmm....why I can't get the output?? any wrong ?? thx for helping...

#include <iostream>
using namespace std;

const int SIZE = 3;
class Course {
    string* students;
  public:
    Course (string* students);
    ~Course ();
    void print();
};

Course::Course (string* students) {
    students = new string[SIZE];
    for(int i=0; i<SIZE; i++){
         students[i]=Course.students[i];
        }
}

Course::~Course() {
  delete [] students;
}

void Course::print() {
  cout << "Students = ";
  for (int i = 0; i < SIZE; i++)
     cout << students[i] << " ";
  cout << endl;
}

int main() {
  string s1[] = {"aaa", "bbb", "ccc"};
  Course c1(s1);
  c1.print();
  string s2[] = {"xxx", "yyy", "zzz"};
  Course c2(s2);
  c2.print();

  return 0;
}

first please use the [ code ] and [ / code ] tags.

The line

students[i]=Course.students[i];

contain an error.it should be like this.

Course::Course (string* students) 
{
    [B]this->students = new string[SIZE];[/B]
    for(int i=0; i<SIZE; i++)
    {
           [B]this->students[i]=students[i];[/B]
    }
}

you have to use this , and note that this is a pointer so you have to use '->' operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.