Skip to content

Compilation error using "template <class T>" (prototypes generated incorrectly) [imported] #472

Closed
@cmaglie

Description

@cmaglie

This is Issue 472 moved from a Google Code project.
Added by 2011-02-06T15:31:57.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium, Component-IDE, Component-PreProcessor

Original description

I found an error using the last revision of Arduino IDE (0022).
This code doesn't compile correctly:

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


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

The IDE returns this error:
error: expected ',' or '...' before '&' token
error: ISO C++ forbids declaration of 'T' with no type
error: 'T' has not been declared

Using version 0021 it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: PreprocessorThe Arduino sketch preprocessor converts .ino files into C++ code before compilationType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions