-
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! :)
-
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;
}
-
Thanks for the help scott, it works fine now.
-
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