jinpenghf 发表于 2015-4-21 14:23:16

库中函数的继承

写了一段代码,但是发现代码太长,自己写了一个库,但是这个库的调用其他库的函数,写过之后一直报错,想知道那位大神能贴一个这样的库膜拜一下!

Super169 发表于 2015-4-21 18:06:38

jinpenghf 发表于 2015-4-21 16:16 static/image/common/back.gif
按照大神的方法,随便写了一个,报错和之前的是一样的
#include
#include


"报错和之前的是一样", 你一直都不把報錯的內容說出來, 是要跟大家玩猜謎遊戲?

雖然單看程式有可能會猜到問題, 但同一個程式也可以有很多不同的問題.
而且, 你貼出來的, 只是整個程式的一部份, 問題是否在這裡也不知.

既然你手上有"报错"的訊息, 為什麼不貼出來, 方便大家呢?

如果真的想解決問題, 最好把你的程式貼上來, 再加上有關的錯誤訊息, 大家就不用瞎猜了.

Super169 发表于 2015-4-21 15:03:30

可以看看 SoftwareSerial 的庫吧, 它就是 继承stream 的.
印象中系統中應該有不少庫都是 继承 stream 的.至於 调用其他库的函数 就更多了.

或者你把你 调用其他库的函数 出錯的部份 以及 報錯的訊息 放出來, 看看問題在那裡吧.

jinpenghf 发表于 2015-4-21 16:16:26

本帖最后由 jinpenghf 于 2015-4-21 16:20 编辑

Super169 发表于 2015-4-21 15:03 static/image/common/back.gif
可以看看 SoftwareSerial 的庫吧, 它就是 继承stream 的.
印象中系統中應該有不少庫都是 继承 stream 的 ...

按照大神的方法,随便写了一个,报错和之前的是一样的
#include <Arduino.h>
#include <uTT.h>
#include <UTFT.h>
#include <avr/pgmspace.h>



void uTT::drawNumBtn(int id,int x,int y,int width,int height,int red,int green,int blue){
    uTFT.setColor(red, green, blue);
    uTFT.fillRoundRect (x, y, x+width, y+height);
    uTFT.printNumI(x+1, x+int(width/2), y+int(height/2));
}

jinpenghf 发表于 2015-4-21 16:16:49

Super169 发表于 2015-4-21 15:03 static/image/common/back.gif
可以看看 SoftwareSerial 的庫吧, 它就是 继承stream 的.
印象中系統中應該有不少庫都是 继承 stream 的 ...

#ifndef uTT_h
#define uTT_h
#endif

#include "Arduino.h"
#include "UTFT.h"
class uTT:public UTFT
{
        public:
                void drawNumBtn(int id,int x,int y,int width,int height,int red,int green,int blue);
        };

jinpenghf 发表于 2015-4-21 16:17:08

Super169 发表于 2015-4-21 15:03 static/image/common/back.gif
可以看看 SoftwareSerial 的庫吧, 它就是 继承stream 的.
印象中系統中應該有不少庫都是 继承 stream 的 ...

#ifndef uTT_h
#define uTT_h
#endif

#include "Arduino.h"
#include "UTFT.h"
class uTT:public UTFT
{
        public:
                void drawNumBtn(int id,int x,int y,int width,int height,int red,int green,int blue);
        };

jinpenghf 发表于 2015-4-21 16:18:45

Super169 发表于 2015-4-21 15:03 static/image/common/back.gif
可以看看 SoftwareSerial 的庫吧, 它就是 继承stream 的.
印象中系統中應該有不少庫都是 继承 stream 的 ...

出错内容      
    \Arduino\libraries\uTT/uTT.h:6:18: fatal error: UTFT.h: No such file or directory
#include "UTFT.h"

谢谢大神了

tsaiwn 发表于 2015-4-21 16:38:43

jinpenghf 发表于 2015-4-21 16:18 static/image/common/back.gif
出错内容      
    \Arduino\libraries\uTT/uTT.h:6:18: fatal error: UTFT.h: No such file or dire ...


先把以下这两句
#include <uTT.h>
#include <UTFT.h>
改为以下看看
#include "uTT.h"
#include "UTFT.h"
注意大小写字母

tsaiwn 发表于 2015-4-21 16:39:07

jinpenghf 发表于 2015-4-21 16:18 static/image/common/back.gif
出错内容      
    \Arduino\libraries\uTT/uTT.h:6:18: fatal error: UTFT.h: No such file or dire ...



除了注意大小写字母
还要注意 #include 时写 "UTFT.h"和 <UTFT.h> 是不一样的 !!
建议通通写 #include "....h"
因为该写 #include <..h>的可用 #include "..h"   取代,
但是反过来是不行的!!
尤其是自己写的库, 如果用到的是 libraries 内的库,
那一定不可以用 <..h>
如果是在 core\arduino 内的核心库则 用 <..h> 是 OK



tsaiwn 发表于 2015-4-21 16:41:28

jinpenghf 发表于 2015-4-21 16:18 static/image/common/back.gif
出错内容      
    \Arduino\libraries\uTT/uTT.h:6:18: fatal error: UTFT.h: No such file or dire ...



還有,
在 libraries 目錄之下各庫的目錄名稱是不重要的,
在該目錄之下各庫之間互相調用必須用 #include "....h"這種寫法,
不然就會找不到庫

jinpenghf 发表于 2015-4-21 17:47:15

tsaiwn 发表于 2015-4-21 16:41 static/image/common/back.gif
還有,
在 libraries 目錄之下各庫的目錄名稱是不重要的,
在該目錄之下各庫之間互相調用必須用 #inc ...

试过还是不行,问题依旧

jinpenghf 发表于 2015-4-21 17:58:27

希望大神能上传一个供大家参考

tsaiwn 发表于 2015-4-22 01:01:07

jinpenghf 发表于 2015-4-21 17:47 static/image/common/back.gif
试过还是不行,问题依旧

把你的(1) .h(2) .cpp   (3) sketch .ino
都贴上来看看
页: [1]
查看完整版本: 库中函数的继承