Forum: C++ Apr 6th, 2009 |
| Replies: 2 Views: 385 Hello I am currently making a program for a database which includes an SSN. The user can input the ssn but I want it in xxx-xx-xxxx and to make sure the user ddoes this have the user input 3 numbers... |
Forum: C++ Mar 31st, 2009 |
| Replies: 7 Views: 638 Okay I finished the program to test all the theories running amuck:
inheritance.h
#include<iostream>
using namespace std;
class base
{
public:
base()
{ |
Forum: C++ Mar 30th, 2009 |
| Replies: 7 Views: 638 Well when a derived object is declared then the derived class inherits the public and protected variables and functions, not the private variables or functions of the base class. I was wondering what... |
Forum: C++ Mar 30th, 2009 |
| Replies: 4 Views: 560 OMG thank you! IT WORKS :}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} When would you use string vs. char arrays? |
Forum: C++ Mar 30th, 2009 |
| Replies: 4 Views: 560 I have been trying to make a program that uses derived classes but have run into a problem. I get the error type: " error C2440: '=' : cannot convert from 'const char [16]' to 'char' " when I try and... |
Forum: C++ Mar 30th, 2009 |
| Replies: 7 Views: 638 It is my understanding that in C++ objects of derived classes invoke the derived class' constructor but before the body is executed the base class' constructor is invoked and takes effect and then... |
Forum: C++ Mar 29th, 2009 |
| Replies: 5 Views: 391 Also, What happens if the constructor tries to initializ a variable that wasn't inherited? |
Forum: C++ Mar 29th, 2009 |
| Replies: 5 Views: 391 Yes but doesn't it seem terribly inefficient to call all of the constructors in that order automatically? Is there any way to stop it? |
Forum: C++ Mar 29th, 2009 |
| Replies: 5 Views: 391 I was testing which constructors are called in when a derived and then base class objects are created. My program couted 0 if it was the base class and 1 if it was the base class. I ran it and it... |
Forum: C++ Mar 29th, 2009 |
| Replies: 3 Views: 266 Yes but what is the reasoning behind not allowing it syntactically? |
Forum: C++ Mar 29th, 2009 |
| Replies: 3 Views: 266 My textbook says "Constructors cannot be virtual. (Think about it: constructors are called to create new objects. However, if you don't know what type of object you're trying to create, how do you... |
Forum: C++ Mar 28th, 2009 |
| Replies: 2 Views: 238 Ohh okay, but b is a base class reference to d so without the virtual keyword in front of base's int get_tag() why doesn't it call the derived version? |
Forum: C++ Mar 28th, 2009 |
| Replies: 2 Views: 238 Hello I have been trying to understand virtual functions for a while and when I made a program to demonstrate the use of virtual functions it didn't and someone gave me this piece of code that would... |
Forum: C++ Mar 22nd, 2009 |
| Replies: 7 Views: 258 I have recently learned about virtual functions and it is to my understanding that they are a keyword that goes in front of the return type when defining a function. They go in a base class, and make... |
Forum: C++ Mar 8th, 2009 |
| Replies: 2 Views: 377 They need to be either constructors or overloaded operators but either way member functions because that is the assignment. Thanks though |
Forum: C++ Mar 8th, 2009 |
| Replies: 2 Views: 377 Hello, I posted a program about converting furlongs to kilometers and other conversions concerning those 2 main units. These errors kept popping up:
error C2027: use of undefined type... |
Forum: C++ Mar 8th, 2009 |
| Replies: 3 Views: 379 Yes that worked but I also needed to put the private int Kilometer and double meter and the getmeter() and getkilometer() functions in there too. BUT there are more functions in the program that if I... |
Forum: C++ Mar 8th, 2009 |
| Replies: 3 Views: 379 Hello, I have been working a week on this program with this stupid bug that gives tons of errors. I have narrowed them down to 4 errors and 2 warnings but I have no idea how to fix the 4 errors.
... |
Forum: C++ Feb 13th, 2009 |
| Replies: 5 Views: 383 so this is a totally different use of the & operator that I was not aware of? Or is this use of the & operator used in that case only, with objects in functions? |
Forum: C++ Feb 10th, 2009 |
| Replies: 5 Views: 383 Sorry I was working on complex copies when I screwed line 10 up, but what my real focus was was:
If in the main you said class box b(a); it would work as expected. But I don't understand how that... |
Forum: C++ Feb 9th, 2009 |
| Replies: 5 Views: 383 I just have one question, when you have a class that is defined:
class box{
public:
int *value;
box()
{
value=new int;
... |
Forum: C++ Feb 9th, 2009 |
| Replies: 12 Views: 623 Oh okay thank you, also how would you create a complex copy constructor? I succeeded in making an explicit shallow copy constructor however in the line "value=c.value;" I have been trying to put... |
Forum: C++ Feb 9th, 2009 |
| Replies: 4 Views: 641 Thank you Sky Diploma, jencas, and kbshibukumar the site and your advice was very helpful. So basiclly what you were all saying was that the copy constructor and assignment operator are 2 different... |
Forum: C++ Feb 9th, 2009 |
| Replies: 12 Views: 623 sorry that last post was badly stated as a question, what I meant was: When p=q calls an overloaded assignment operator and preforms a shallow copy is this done using the automatic copy constructor... |
Forum: C++ Feb 9th, 2009 |
| Replies: 4 Views: 641 If an explicit copy constructor is defined that makes a complex copy, does:
int main()
{
class shoe shoe1;
class shoe shoe_copy(shoe1);
}
And |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 623 Ohhhh... okay that is probably the most informative clear article I have read on the subject and I thank you for that excellent link.
So when p=q calls the copy constructor is this accessing a... |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 623 but the last example shoe_copy=shoe1; - does that set the adresses equal or what does it physically do to shoe_copy. |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 623 yes but what willl shoe_copy=shoe1 do? |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 623 So when two objects are declared say class shoe shoe1 and class shoe shoe_copy and then shoe1's variables are set, if the line of code: shoe_copy=shoe1; what would that be doing? After all what is... |
Forum: C++ Feb 6th, 2009 |
| Replies: 2 Views: 247 Thanks RenjithVR , I now think I understand copy construcotrs better but just 1 more question: when you call abc(diatance b) to a (distance &c) function definition should you rather call abc(distance... |
Forum: C++ Feb 6th, 2009 |
| Replies: 2 Views: 247 When a parameter in a function definition (for say class distance) is abc(distance a) and in the main you call this function and pass distance b, what is the relationship thereafter between distance... |
Forum: C++ Feb 5th, 2009 |
| Replies: 8 Views: 481 |
Forum: C++ Feb 5th, 2009 |
| Replies: 8 Views: 481 So when you say to pass by reference do you mean to just pass box b= box(&a) or to pass b=box(a) to the copy constructor that is defined by box( box &b){..} in the class?
Also, what is the class... |
Forum: C++ Feb 5th, 2009 |
| Replies: 8 Views: 481 Does the new need to be there in the box b= new box(c)?
When the program passes box(c) to the parameter box( box d){this.value=d.value}
What happens with objects c and d? Do there adresses become... |
Forum: C++ Feb 5th, 2009 |
| Replies: 8 Views: 481 My questions following woll refer to this program shown later in the article:
box.h:
class box{
private:
int value;
public:
void def_v(int in) //define value
{this.value=in;}
void... |
Forum: C++ Feb 4th, 2009 |
| Replies: 8 Views: 481 Hello I was researching the copy constructor and found this exampleo a website:
#include <iostream>
class Array
{
public:
int size;
int* data; |
Forum: C Feb 4th, 2009 |
| Replies: 4 Views: 1,144 Hi lately i have been studying the malloc and calloc functions for dynamically allocating memory. I thought the form was:
(data_type*) malloc(data_size);
But then I stumbled onto this code... |
Forum: C++ Feb 1st, 2009 |
| Replies: 1 Views: 270 When a pointer is deleted, is the memory it is pointing to only returned to the heap or is it also nulled too? Thx |
Forum: C++ Feb 1st, 2009 |
| Replies: 1 Views: 267 Say I have a class (say number) and declare a private variable (say int num) and have a public member function(say int getnum() ) that retrieves the private variable. When I in the main() without... |
Forum: C++ Jan 27th, 2009 |
| Replies: 2 Views: 929 Hi I have to do an assignment for a course that includes that I use new stream insertion and stream extraction techniques. On the lecture notes it briefly mentioned cin.get() and getline but not in a... |