类的指针问题,请教大大
class Test
{
private:
char *pc;
public:
void outText(char *);
};
Test::Test()
{
this-> pc=NULL;
}
void Test::outText(char *text)
{
this-> pc=text;
for(int i=0;i <5;i++)
{
printf( "%c\n ",this-> pc);
this-> pc++;
}
}
-----------------------------------------------
代码如上,类的成员是个char的指针.
在函数outText(char *)把类成员的指针指向参数.
this-> pc 这句指的是 *pc 还是 pc 的意思阿.?
this-> pc++ 是不是等于 pc++ 阿?怎么我传进去 "abcde "输出来的东西都是其它字符的.?
我的函数就是实现把传进去的参数每个字符的都赋给pc,然后用pc输出每个字符.
但搞不明白类成员指针的问题.请教大大..
[解决办法]
#include <iostream>
#include <stdlib.h>
using namespace std;
class Test
{
private:
char *pc;
public:
Test();
void outText(char *);
};
Test::Test()
{
this-> pc=NULL;
}
void Test::outText(char *text)
{
this-> pc=text;
for(int i=0;i <5;i++)
{
printf( "%c\n ",*this-> pc);
this-> pc++;
}
}
void main()
{
Test ts;
ts.outText( "abcde ");
system( "PAUSE ");
}