|
-
Feb 9th, 2001, 10:54 PM
#1
Thread Starter
PowerPoster
Hi, i am trying just to get classes down, and i think the class itself is ok. But whenever i try to compile this code i get errors about casting a and b to a char. They already are a char! I have no idea what is wrong.
I know the code is useless and pointless, like i said, i am just trying to get this down.
Code:
#include <iostream.h>
class Func {
public:
void Welcome(char name);
};
void Func::Welcome(char name) {
cout<<"Welcome to my program"<<name<<endl;
}
char a = "Hi";
char b = "Hello";
int main(){
Func Start;
Start.Welcome(a);
Start.Welcome(b);
return 0;
}
Thanks A LOT for any help!
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Feb 10th, 2001, 01:44 AM
#2
Addicted Member
Try This
char our one byte so to place a string in them you use a array for the number a char you want plus one for the null terminator
#include <iostream.h>
class Func
{
public:
void Welcome(char name[]);
};
void Func::Welcome(char name[])
{
cout<<"Welcome to my program "<<name<<endl;
}
char a[3] = "Hi";
char b[6] = "Hello";
int main()
{
Func Start;
Start.Welcome(a);
Start.Welcome(b);
return 0;
}
-
Feb 10th, 2001, 02:11 AM
#3
Thread Starter
PowerPoster
Thanks for the help scott, it works fine now.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Feb 10th, 2001, 08:52 AM
#4
Monday Morning Lunatic
And you can also make it simpler by using
char *pcStr = "Hello";
But bear in mind that this allows you to change the pointer if you really want to
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|