PDA

Click to See Complete Forum and Search --> : Easy question i think


sail3005
Feb 9th, 2001, 09:54 PM
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.



#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! :)

ScottF
Feb 10th, 2001, 12:44 AM
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;
}

sail3005
Feb 10th, 2001, 01:11 AM
Thanks for the help scott, it works fine now.

parksie
Feb 10th, 2001, 07:52 AM
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 :p