I'm so sorry guys, I hate myself right now...sometimes I miss the smallest inconsequential details and I go look for an error somewhere else, and I do have problem reading and interpreting the errors...
Type: Posts; User: Ashl7
I'm so sorry guys, I hate myself right now...sometimes I miss the smallest inconsequential details and I go look for an error somewhere else, and I do have problem reading and interpreting the errors...
can't figure it out for the life of me.
@phantomotap: you mean I should define it in a way that it gets a null pointer?! (explain pls)
I get this error, it is very long!!
e:\users\ashl7\desktop\sodacan2012\sodacan2012\sodacan.cpp(86): error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const...
Yeah I missed in when I was copy/pasting....but the brace was already in my code!
Ok, I've changed the message, and I'm going to be content with cout message to inform the user about the NULL pointer.
So, next is overloading >> operator. here's my definition for it:
...
Thanks guys, I think what the teacher wants us is just to check if the pointer sent to the overloaded function is NULL or not, if it is, show an error(either on screen or using exception handeling)...
uuugh! god!! I even declare it with const in my header file, but missed it in my definition....thank you!
any thoughts on the second question?! a way to work with NULL pointer on this class?
Answer to No.2 question:
apparently I can't do that! In the driver code by my teacher, we need to print an object of the class without using pointers
/// junk should have 76 ounces
junk =...
Wow I totally missed that this thread went to the second page! :frown:
First of all, thanks everyone for the comments.
@Elysia, I decided to remove some of the codes that my teacher had in his...
what does it do?! never read about it!
Should I put it in front of all my functions?! or const functions?! or my overloaded function?
Yess, thanks, I remember in the book it said :
Appreciate it. This problem is fixed, however I still get the error I was getting at first, I have not been able to compile it yet...
1> ...
I didn't say you "have to"....and teaching is helping :)
It does not compile, it says : error C2662: 'SodaCan::getContents' : cannot convert 'this' pointer from 'const SodaCan' to 'SodaCan &'
>...
@grumpy:
I know the definition that you see there was a test, I think this one should work, but it does not:
ostream& operator <<( std::ostream& outs, const SodaCan *can ){
...
And here's my application file(which I did not write, the teacher did), however, the other overloaded functions( ==,>, < etc.) are written by me:
#include <iostream>
#include <string>...
@Laserlight:
I know, passing pointers to functions and overloading is troublesome, but this is the way the teacher wants us to do...
thanks for reminding me about namespace std, and then using...
What do u mean by a "valid pointer"?
My application file looks fine...I have:
SodaCan * ptrCan = new SodaCan( "Coke", 25, 3 );
SodaCan * nullCan = NULL;
cout << nullCan << endl;
cout <<...
Hi, I am trying to figure out what's wrong with my code here?
I should overload these two operators using pointers, I know how to overload them without pointers, but I guess I'm making a mistake in...
and why does this one prints out AB?! it should be A itself, since the character in slot 0 is A!!!
#include <stdio.h>
int main()
{
char *ch;
char vch[]={'A','B','\0','C','\0'};
...
Hey all
can anyone explain to me why this program output is AB?
I mean I think it should be ABC?! shouldn't it?!
#include <stdio.h>
int main()
{
char *ch;
char...
I had some question not related to programming this time
Is it necessary to take C++ before taking Java?! is it going to be hard to understand Java if I don't learn C++ in advance?! which one is...
Thank you aaaalllll... really helped me out here :)
STD, the examples were just great!
lol I read that before, but I'm still confused!!!!!!!!!!
questions pouring up...
confirm if this is true:
char f[3];
first character goes to slot 0, second goes to slot 1, third to slot 2, forth is a null character which goes to slot 3.(is it true?)...
another thing...
is there any difference between an array of characters, and string (and c-style string)?! I mean char i[10] is what we call a string, meanwhile it's an array of characters, right?!...