블로그 이미지
.
속눈썹맨

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

C++ template에서는 string literal을 쓰면 안됨

2005. 6. 7. 15:05 | Posted by 속눈썹맨
$ cat ./temp1.cpp
#include <iostream>

extern const char *FOOD_PREFIX = "/tmp/really_hungry"

template<size_t SIZE=8192, const char *PREFIX=FOOD_PREFIX>
class Food
{
    public:
    int m_price[SIZE];
    char *m_prefix;

    Food(const char* prefix=PREFIX) : m_prefix(prefix)
    {
    }
};

int main()
{
    Food<> goodFood;

    goodFood.m_price[0] = 100;

    return 0;
}

[ilashman@ob test_shm2]$ g++ ./temp1.cpp -g -Wall
temp1.cpp: In function `int main()':
temp1.cpp:17: string literal "/tmp/really_hungry" is not a valid template argument because it is the address of an object with static linkage
temp1.cpp:17: ISO C++ forbids declaration of `goodFood' with no type
temp1.cpp:19: request for member `m_price' in `goodFood', which is of
   non-aggregate type `int'

C++ 표준보기

http://library.n0i.net/programming/c/cp-iso/template.html
14.3.2 -2-을 보면
template에서는 string literal을 쓰면 안됨.