performance problems

I have a problem.
i have a performance problem in my code.
the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
class Person{
private:
  std::string name;
  std::string add;
public:
 Person();
 virtual ~Person();
 //...
};

class Student: public Person{
private:
 std::string schoolName;
 std::string schoolAdd;
public:
 Student();
 ~Student()
 //...
};

int main(int argc, char ** argv){
 //...
 bool validateStudent(Student s);

 Student fourrier;
 bool fourrierIsOK = validateStudent(fourrier);
 //..
}


could be the virtual destructor?
I can't understand what is the problem.
thanks
Last edited on
There's no destructing going on in the snippet you posted, so probably not.
validateStudent() seems like the most likely suspect, but you've posted really little code.
Also, are you sure that particular section is the one taking most of the time?
The function validateStudent() creates a copy of the student class, but you haven't declared a copy constructor.
Copy constructor isn't needed since the default one will suffice.

We need to see the code for validateStudent(), constructors, destructors, and any functions that validateStudent() calls.
I'm sour that this is the part whit de performance problem. My teacher cut and mail it to me like i post.

He told me that the other part of the code is good and i must forget it, i must focus about this problem, and it is their.

I have asked my friends if they know what is wrong but no one have shore about it.

please, help me

Last edited on
All I can think of without looking at more code is that he meant that the function should take a reference/pointer to a Student, rather than a Student itself. Although that hardly counts as a performance problem (at least not when outside a loop).
You don't need to copy the Student object when passing it to the validateStudent method. Pass it as: const Student & s.

I'm a big fan of virtual destructors in classes intended to be inherited from; but it does hit performance (a little tiny bit)...

Also, note that there are private members in the base class; they would not be inherited. This is the biggest problem that I see in the snippet above.
Last edited on
IMO. It maybe the application design.

Each person has a Name and Add,
Each Student is a person who goes to a school. A student shouldn't have a SchoolName and SchoolAdd parameter, but should have a pointer to a School object.

*shrug*. My 2c
Topic archived. No new replies allowed.