ferguson32's Profile User Rating: -----

Reputation: 0 Apprentice
Active Members
Active Posts:
178 (0.23 per day)
29-May 12
Profile Views:
Last Active:
User is offline Jul 30 2013 07:49 PM

Previous Fields

Dream Kudos:
Icon   ferguson32 has not set their status

Posts I've Made

  1. In Topic: general c++ questions

    Posted 25 Jul 2013

    Hows this for 2 and 3

    2. C++ allows constructor overloading. Why doesn't it allow
    destructor overloading?

    Normally you never explicitly call the destructor, it is automatically called by the C++ frame work when the object is deleted/goes out of scope. Therefore you would not need to overload the destructor because the frame work always calls the default destructor. Additionally the C++ standard defines that a conforming compiler only allows for 1 destructor per class.

    3. When enabling a class to work with iostreams by adding overloaded
    operator<< and operator>> functions, should they be friends
    of the class or member functions, and why?

    When you use these as stream operators the first parameter is a stream. Since you do not have access to the stream object these cannot be member operators they have to be external to the class. Thus they must either be friends of the class or have access to a public method that will do the streaming for you.
  2. In Topic: Rolodex project

    Posted 17 Jul 2013

    Would it just be

    os << lastName << firstName << occupation << address << phoneNumber;
  3. In Topic: Rolodex project

    Posted 17 Jul 2013

    Thank you, I do use that site a lot but it confuses me sometimes. Like the show function in the card class is to display the card on the supplied ostream parameter. I was on the C++ site reading about ostream but I am not supposed to use cout, and that is all I see when it comes to displaying something. Is there another way to display these member variables to "os"?

    I have this right now:
    string Card::show(ostream& os)
    	os =  lastName << firstName << occupation << address << phoneNumber;
  4. In Topic: Rolodex project

    Posted 17 Jul 2013

    Well I'm new to programming so I at the moment I am having difficulty coding the functions properly. Like for starters could you help me fix the add function in my rolodex class? As I said above ittakes a Card object as a parameter (by ref is more efficient), adds it to the STL container member (in the appropriate spot so the cards are kept in alphabetical order by [last name, first name]), and sets it as the 'current card' in the Rolodex by setting the STL iterator member to point at the Card just added..

    I thought the code should be like this:

    void Rolodex::add(Card& card)
    	currentCard -> card;
    	sort(list.begin(), list.end());

    Isn't it adding the card to the vector list, then pointing the current card to that card, and finally sorting the list? The second line is giving an error, saying card is not a function of class Card so I don't understand how to point to set the current card to the parameter card.
  5. In Topic: Shape class

    Posted 11 Jul 2013

    Why doesn't this work for main? It keeps setting the return value of getShape to the array pointer "shape" and then sends shape to the toString function. Maybe my toString is not right? Here is the one for class circle, because that is what I have been testing with

    #include "stdafx.h"
    #include <string>
    #include <sstream>
    #include "Shape.h"
    #include <iostream>
    using namespace std;
    Shape* getShape();
    int _tmain(int argc, _TCHAR* argv[])
    	 cout << "Enter a list of shapes - 'done' to end" << endl;
    	 Shape* shape = NULL;
    	 while(getShape() != NULL)
    		 shape = getShape();
    	 cout << shape << endl;
    	return 0;

    string Circle::toString()
    	std::ostringstream oss;
    	oss << "" << getColor() << "circle with a radius"  << ""<< area();
      std::string s = oss.str();
      return s;

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



ferguson32 hasn't added any friends yet.


ferguson32 has no profile comments yet. Why not say hello?