CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: heat89

Page 1 of 2 1 2

Search: Search took 0.03 seconds.

  1. Replies
    1
    Views
    700

    writing to a file (problem with file

    #include <iostream>
    #include <fstream> //allow writing to file instead of cout
    #include <cstring>
    using namespace std;
    #include "date.h"
    #include "person.h"
    #include "student.h"
    #include...
  2. Replies
    12
    Views
    1,634

    Re: Problem with inheritance

    Thanks for the help.

    No the copy constructor was not complete at that time, I have since attempted to complete it:



    class Student : public Person {
    public:
    Student(const char *...
  3. Replies
    12
    Views
    1,634

    Re: Problem with inheritance

    Thanks for the help.

    I'd like to understand a little more though instead of just pasting in what you're telling me to. I was under the impression that the copy constructor is perfectly defined...
  4. Replies
    12
    Views
    1,634

    Re: Problem with inheritance

    I see, any tips on how to make it defined? I tried to stick an int in front of it (semi-knowing it wouldn't work) and it gave me lots of errors so I'm thinking that isn't the way to get it done.
  5. Replies
    12
    Views
    1,634

    Re: Problem with inheritance

    See I tried that before posting here for some help by doing



    class Student : public Person {
    public:
    Student(const char * their_name, const char * email, const Date & d, const char * sch,...
  6. Replies
    12
    Views
    1,634

    Problem with inheritance

    So I have a Person class which is the base class for another class called Student (inherits from Person).

    I'm getting a couple errors but I'm not sure where they are coming from...

    Person...
  7. Re: What is the difference between a copy constructor and assignment operator?

    Thanks for the help.

    Does the new object have to be the same type as the existing object?
  8. What is the difference between a copy constructor and assignment operator?

    Also when and why should they be used?

    I know you are given them both for free if you don't assign them, but why do we need to assign them in the first place?
  9. Re: Can somebody help me understand this ouput? (Copy constructors/Assignment Operato

    Ok so I see why A() is being printed first, I'm guessing because there's no initializer list it goes to the that reads A a in the B class which in turn goes to A() method which prints out "A()".
    ...
  10. Can somebody help me understand this ouput? (Copy constructors/Assignment Operators)

    Here is some code that puts to use copy constructors and assignment operators:



    #include <iostream>
    using namespace std;

    class A {
    int n;
    public:
  11. Re: Deleting first element in an array, and substituting the next object as the new f

    Oh I see what you mean, ok thanks I'm going to try and approach this from another angle, thanks for your help!
  12. Re: Deleting first element in an array, and substituting the next object as the new f

    Do you mind clarifying what you mean by the delete element[0] statement deletes the same element? Do you mean it deletes the same element the second time its called? Or are you saying even the first...
  13. Re: Deleting first element in an array, and substituting the next object as the new f

    Thanks, I will make the appropriate changes as you suggested, it should be numberOfElements in the for-loop.

    Here is my main:



    #include <iostream>
    #include "date.h"
    #include "loan.h" ...
  14. Re: Deleting first element in an array, and substituting the next object as the new f

    void add(Loan & aLoan)
    {

    if (numberOfElements == capacity)
    {
    std::cout << "Container is growing.\n";
    Loan ** temp = elements;
    elements = new Loan*[capacity*2];
    for(int i=0;...
  15. Re: Deleting first element in an array, and substituting the next object as the new f

    So that's why my program is crashing then right?

    What is the appropriate method of deleting the first element from the elements array then?
  16. Re: Deleting first element in an array, and substituting the next object as the new f

    A thought just came to me, I'm creating the array like this:

    elements = new Loan*[initial_size];

    is delete elements[0] even the right way of deleting the first element? I seem to remember my...
  17. Re: Deleting first element in an array, and substituting the next object as the new f

    Well it still crashes at the same spot, but I will work with what I have, thanks again.
  18. Re: Deleting first element in an array, and substituting the next object as the new f

    That would be elements[2] = elements[3] actually.
  19. Re: Deleting first element in an array, and substituting the next object as the new f

    Yes I think so.

    If we have 3 elements, then my for-loop was telling the program to do elements[3] = elements[4]. Can't happen though if there's only 3 elements to begin with. Does that sound about...
  20. Re: Deleting first element in an array, and substituting the next object as the new f

    Yeah I understand that, of course I don't expect anyone to have a specific answer to this right off the bat, but I do appreciate all the advice, generic or not it does help me understand different...
  21. Re: Deleting first element in an array, and substituting the next object as the new f

    Thanks for the reply Paul,

    Even as a beginner programmer (especially in C++) there are things I know I'd do differently/more efficiently if it were up to me, but since these are part of assignment...
  22. Re: Deleting first element in an array, and substituting the next object as the new f

    Well here's the part of the main function which I'm calling the removeFirst() method from:



    for(int i = 0; i<numberOfCarLoans ; i++)
    {
    Loan & aLoan = carLoans.removeFirst(); //important...
  23. Re: Deleting first element in an array, and substituting the next object as the new f

    for (int i = 0; i < numberOfElements; i++)
    {
    elements[i] = elements[i + 1];
    }


    Does that look better?

    It still seems to crash after deleting the first element.
  24. Re: Deleting first element in an array, and substituting the next object as the new f

    What are you talking about?
  25. Re: Deleting first element in an array, and substituting the next object as the new f

    Sorry I hadn't checked his reply here when I posted that.
Results 1 to 25 of 45
Page 1 of 2 1 2





Click Here to Expand Forum to Full Width

Featured