QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1038|回复: 8

c++的疑惑

[复制链接]
发表于 2005-7-9 15:27:12 | 显示全部楼层 |阅读模式
在很多C++程序中都能看到类似下面的语句
*p  
我知道,这是说明p是个指针,但下面的我就弄不明白了
p*
这是什么意思呀,很多国外的程序都能见到这种语句,我真的给弄糊涂了。
发表于 2005-7-9 18:05:53 | 显示全部楼层
e.g.
typedef int MyType;

MyType* p;       //定义p,p为指向MyType的指针
回复

使用道具 举报

发表于 2005-7-9 20:03:20 | 显示全部楼层
写一个例子出来,好像没有见过你说的用法.
回复

使用道具 举报

发表于 2005-7-9 21:38:11 | 显示全部楼层
QString *qs = new QString;
回复

使用道具 举报

 楼主| 发表于 2005-7-10 07:15:32 | 显示全部楼层
原来是自己定义的类型呀
回复

使用道具 举报

 楼主| 发表于 2005-7-10 07:18:32 | 显示全部楼层
#include <iostream>
#include "../libloader/libloader.h"
#include "../abstract/database.h"
#include "../abstract/cursor.h"

int main (int argc, char * const argv[])
{

   CMK::LibLoader load;
   CMK::Database* db = load.load("/usr/lib/libpostgresqldriver.dylib");
       
   db->setUsername("postgres");
   db->setHost("localhost");
   db->setPassword("");
   db->setDatabase("test");

   if(db->connect())
   {
       CMK::Cursor* cursor = db->createCursor();
       if(cursor->query("select * from t1"))
        {
           while(cursor->next())
               {
                        std::cout << "\n" << cursor->value(0) << "\n";
                 }
         }
  }
  return 0;
}
上面的 CMK::Database* db是不是就是自己定义的类型呢?
回复

使用道具 举报

发表于 2005-7-10 08:03:11 | 显示全部楼层
类型 *p = new 类型;
回复

使用道具 举报

发表于 2005-7-10 11:57:50 | 显示全部楼层
[quote:320c82848d="zzh2004linux"]#include <iostream>
#include "../libloader/libloader.h"
#include "../abstract/database.h"
#include "../abstract/cursor.h"

int main (int argc, char * const argv[])
{

   CMK::LibLoader load;
   CMK::Database* db = load.load("/usr/lib/libpostgresqldriver.dylib");
       
   db->setUsername("postgres");
   db->setHost("localhost");
   db->setPassword("");
   db->setDatabase("test");

   if(db->connect())
   {
       CMK::Cursor* cursor = db->createCursor();
       if(cursor->query("select * from t1"))
        {
           while(cursor->next())
               {
                        std::cout << "\n" << cursor->value(0) << "\n";
                 }
         }
  }
  return 0;
}
上面的 CMK::Database* db是不是就是自己定义的类型呢?[/quote]

那就是我之前说的情况了
回复

使用道具 举报

发表于 2005-7-11 03:19:31 | 显示全部楼层
char* c
char *c
char * c
以上三种写法没有任何曲被,所以:
class p
{
...
};

p* var;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-20 08:29 , Processed in 0.135612 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表