# 問題 'T' does not name a type

**URL:** <https://forum.arduino.cc/t/t-does-not-name-a-type/329988>\
**Category:** 中文 (Chinese)\
**Created:** [August 17, 2015, 1:52am UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988 "2015-08-17T01:52:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chan40](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@chan40](https://forum.arduino.cc/u/chan40)\
**Post date:** [August 17, 2015, 1:52am UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988/1 "2015-08-17T01:52:12Z")

</div>

下面這是我使用的程式碼  
// Based on I2Cdevlib, MPU6050\_raw  
// Experiments to verify if any data loss when writing MPU6050 outputs to EEPROM

#include "I2Cdev.h"  
#include "MPU6050.h"  
#include \<EEPROM.h\>  
#include "eeprom\_anything.h"

// Arduino Wire library is required if I2Cdev I2CDEV\_ARDUINO\_WIRE implementation  
// is used in I2Cdev.h  
#if I2CDEV\_IMPLEMENTATION == I2CDEV\_ARDUINO\_WIRE  
#include "Wire.h"  
#endif

MPU6050 accelgyro;  
int16\_t ax, ay, az;  
int16\_t gx, gy, gz;

// [eeprom]  
struct accelData{  
int16\_t ax;  
int16\_t ay;  
int16\_t az;  
};  
accelData acc;  
int accIdx = 0;  
int accMem = 0;  
int max = 1024 / sizeof(acc);

void setup() {  
// join I2C bus (I2Cdev library doesn't do this automatically)  
#if I2CDEV\_IMPLEMENTATION == I2CDEV\_ARDUINO\_WIRE  
Wire.begin();  
#elif I2CDEV\_IMPLEMENTATION == I2CDEV\_BUILTIN\_FASTWIRE  
Fastwire::setup(400, true);  
#endif

// initialize serial communication  
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but  
// it's really up to you depending on your project)  
Serial.begin(38400);

// initialize device  
Serial.println("Initializing I2C devices...");  
accelgyro.initialize();

// verify connection  
Serial.println("Testing device connections...");  
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");  
}

void loop() {  
//writeEEPROM();  
dumpEEPROM();  
}

void writeEEPROM()  
{  
// read raw accel/gyro measurements from device  
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

// waive the first 100 sensor data  
if (accIdx \>= 200 && accIdx \< max + 200)  
{  
Serial.print("Idx: "); Serial.print(accIdx-200);  
Serial.print(", ax: "); Serial.print(ax); acc.ax = ax;  
Serial.print(", ay: "); Serial.print(ay); acc.ay = ay;  
Serial.print(", az: "); Serial.println(az); acc.az = az;  
accMem = EEPROM\_writeAnything(accMem, acc);  
}  
accIdx ;  
}

## void dumpEEPROM() { accelData accTmp; int tmpMem = 0; for (int i=0; i\<max; i ) { tmpMem = EEPROM\_readAnything(tmpMem, accTmp); Serial.print("Idx: "); Serial.print(i); Serial.print(", ax: "); Serial.print(accTmp.ax); Serial.print(", ay: "); Serial.print(accTmp.ay); Serial.print(", az: "); Serial.println(accTmp.az); } }

這是我出現的error

MPU6050\_EEPROM:20: error: 'T' does not name a type  
MPU6050\_EEPROM:20: error: ISO C++ forbids declaration of 'value' with no type [-fpermissive]  
MPU6050\_EEPROM:21: error: 'T' has not been declared  
'T' does not name a type

跪求各位大神幫幫我 ~~~~

---

<div class="post-metadata">

**Author:** ![liuzengqiang](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/liuzengqiang/32/213605_2.png) [@liuzengqiang](https://forum.arduino.cc/u/liuzengqiang)\
**Post date:** [September 3, 2015, 5:01am UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988/2 "2015-09-03T05:01:03Z")

</div>

把eeprom\_anything.h内容贴出来吧

---

<div class="post-metadata">

**Author:** ![sonnyyu](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@sonnyyu](https://forum.arduino.cc/u/sonnyyu)\
**Post date:** [September 7, 2015, 3:04am UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988/3 "2015-09-07T03:04:27Z")

</div>

> liudr:  
> 把eeprom\_anything.h内容贴出来吧

```arduino
#include <EEPROM.h>
#include <Arduino.h>  // for type definitions

template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
	  EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
	  *p++ = EEPROM.read(ee++);
    return i;
}

```

[http://playground.arduino.cc/Code/EEPROMWriteAnything](http://playground.arduino.cc/Code/EEPROMWriteAnything)

---

<div class="post-metadata">

**Author:** ![liuzengqiang](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/liuzengqiang/32/213605_2.png) [@liuzengqiang](https://forum.arduino.cc/u/liuzengqiang)\
**Post date:** [September 8, 2015, 5:31am UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988/4 "2015-09-08T05:31:16Z")

</div>

不知道什么神人六七年前写的程序了，有问题只能后果自负。我对Template不熟悉，不好意思。

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 6:03pm UTC](https://forum.arduino.cc/t/t-does-not-name-a-type/329988/5 "2021-05-06T18:03:00Z")

</div>


