I think I got you, thanks!. Its a lot more nuanced than I initially thought.
Type: Posts; User: Vespasian_2
I think I got you, thanks!. Its a lot more nuanced than I initially thought.
I think I got you. Its a lot more nuanced than I initially thought.
OK, I assume that this is also a composition between Driver and license?
class Driver
{
// ...
private:
DrivingLicence *licence = new DrivingLicense;
std::vector<Car*> cars;
Thats the problems i'm having. I cant think of the minimum C++ example that demonstrates the difference between the two. I just know through a textbook that what I included above is composition.
I get that but how would the difference in implementation look? Ill give an example. Ive made 1 superclass called Asset and 3 subclasses which derive from Asset and they are called Stock, Bond and...
I have read all StackOverflow articles. Many other articles. Book posts and blogs and still struggling to understand the difference between the two.
From what I know:
Composition means that if A...
Got it. Thanks again Laserlight, quality response as always.
Is there any benefit to having this:
OPTION 1:
class stackArray{
static const int STACK_SIZE = 3;
public:
stackArray(){
item = new int[STACK_SIZE];
item[0] = 100;
Ok, but is line 20 and 21 specifically a memory leak? I dont see comments next to them in your comments. My rationale is as follows:
Line 20: name = n; // name USED to point to an area of heap...
#include <iostream>
#include <string>
#include <stdlib.h>
#include <string.h>
using namespace std;
class Student{
Thanks all. Makes sense.
In the conditional statement in the while loop below, the extraction operator is used on an input stream object "i". When the file reaches an EOF, the loop breaks.
This doesnt make sense as I...
Ah I never saw it that way. Interesting, makes sense now that I think about it.
I understand. Is there any design rationale behind this (Edit: I mean why was the language designed like this)? If you could evaluate an array name to a modifiable address, you would only lose the...
Suppose we have:
char myString[] = "This is a test";
If I want to delete the first character of an array, I am always tempted to do:
myString1++
The above doesn't work. What does work...
I feel like an idiot. You basically fixed the error before I asked the question, thats a first ive ever seen on a forum.
OH MY WORD EMBARRESING. Sorry you were right tabstop.
There are no more errors
Haha yeah I just saw your reply but I fixed that too it seems there is still the crashing error
Ah thanks! Silly me. Im new to templates as you may see.
Okay Ive just put it in a header only file but now Im getting an error printing out the Object:
#include <iostream>#include "matrix.h"...
I have a Matrix Class defined as follows:
#include "matrix.h"
template <class Object>
Matrix<Object>::Matrix(int row, int col)
{
rows = row;
cols = col;
array.resize(row);
Thanks alot! I didnt know a const would cause a compilation error! I thought at most it was just to remind the reader that it is a value that should not change.
Hi all,
I have overloaded an insertion operator which works on the object within which it is defined (see line 47).
But when I use this insertion operator on an object that contains the other...
Thanks Laserlight that kinda makes sense. But which one of them is more specific as a description for the numeric arrays as an example? What I mean by that is, is there ever a case where the...
I am using a numeric array as an example to my core question.
What happens when an array declaration statement does not provide an initial value for each of the elements in a numeric array?
I...
Is this statement:
if(strcmp(string1, string2))
Equivalent to
if(strcmp(string1, string2) == 0)
My understanding is case 1 is the correct way to execute an if statement if two strings...