极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12391|回复: 1

请教个问题:为什么Wire.write(str);这样写是错的?

[复制链接]
发表于 2014-9-6 20:31:54 | 显示全部楼层 |阅读模式

请教个问题:为什么Wire.write(str);这样写是错的?


老是抱着错误:no matching function for call to 'TwoWire::write(String&)'

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2014-9-7 01:31:34 | 显示全部楼层
不知是那裡出了問題.
在 arduino.cc 中, WireWrite 的 Syntax http://arduino.cc/en/Reference/WireWrite
Wire.write(value)
Wire.write(string)
Wire.write(data, length)

是可以接受 string 參數的.

但在 Wire.h 當中,
  1.     virtual size_t write(uint8_t);
  2.     virtual size_t write(const uint8_t *, size_t);
复制代码


應該是不接受 string 的.

不過, 有一點要注意, syntax 當中的是 string, 而不是 String (class), 意義也有點不同.
基本上, 從庫的設計去看, 我不相信 Wire class 會接受 String 作參數, 因為 String 是一個比較耗資源, 較為高階的 class.
而 Wire 是低階的庫, 絕不應該會調用 String 的.  一般寫庫的人, 也盡量不會用 String class 的.

所以, 我相信 wire 應該不可能接受 String class 的參數.

當然, 這純粹是個人猜測, 如果它真的調用 String class......或許還是有可能吧.(但相信應該機會很微)
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 16:26 , Processed in 0.035140 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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