typedef 로 정의한 함수를 사용할 때 에러가 나요.

easyhe의 이미지

안녕하세요.. typedef에대해서 공부중입니다.

typedef void (FUNC) (void);
class TypeTest{
public:
	static int * sampleFunc(char);
	static FUNC * m_t;
	void func();	
};
 
typedef int * (FUNC2)(char);
FUNC2 * TypeTest::m_t = TypeTest::sampleFunc;
 
int * TypeTest::sampleFunc(char)
{
	int *a,b=0;
	a=&b;
	return a;
}

위의 코드에서 FUNC2 * TypeTest::m_t = TypeTest::sampleFunc; 라고 하면 m_t 가 재정의 되었다고 에러가 납니다..
m_t를 다른 타입으로 바꿀 수 없는 건지요..
typedef는 변수 선언과 조금 다르니까 될 수 있는것 아닌가 해서요..

열심히 내공쌓아서 다음부터는 저도 답글을 달고 시포용..
고수님들 설명 부탁드려요..ㅡㅜ

wsmrdo의 이미지

typedef 과는 상관 없는 겁니다.
m_t 가 위에 선언이 이미 되어 있는거 아닌가요?

panda005의 이미지

타입은 FUNC, FUNC2이고
m_t는 그냥 변수죠...

int m_t;
char m_t;

이거랑 같은 결과입니다.
변수명을 바꿔주시는 게...

wsmrdo의 이미지

typedef <-- 이것과 에러는 상관이 없다는 말입니다.

m_t 가 중복 선언 된것이 문제된거로 메세지가 나왔다 하셨고.

실제 클래스 내부에서
char i;
int i;
의 형태로 중복 사용이 가능한 것은 알고
그 바깥에서 사용하셨고,
이미 클래스 내부에서 사용된 변수를 사용하셨으니 말입니다.

클래쓰 바깥에서... 추가로 선언하는 게 되나요?
new 처럼... 왠지 표준에 벗어난거 같네요 ..

인용:
class TypeTest{
public:
static int * sampleFunc(char);
static FUNC * m_t;
void func();
};

typedef int * (FUNC2)(char);
FUNC2 * TypeTest::m_t = TypeTest::sampleFunc;

이거를.
바꿈:
typedef int * (FUNC2)(char);

class TypeTest{
public:
static int * sampleFunc(char);
static FUNC * m_t;
FUNC2 * m_t = TypeTest::sampleFunc;
void func();
};

이런식으로 바꾸어야 panda005 님이 말씀하신 것에 맞겠는데요.

뭐 이것도 제대로 될지는 의심스럽지만.... ^^;;

C 에 뿔이난걸 두려워하는 一人 이었습니다.

easyhe의 이미지

답글감사드립니다..
wsmrdo 이 말씀하신대로 입니다..typedef 와 관계가 없네요..

그래서 이번에는 ..
m_t를 static 으로 선언했으므로, 클래스 외부에서 타입변경의 가능 여부로 생각해 보고 있습니다.

어떻습니까..
답글 애타게 기다리고 있습니다..ㅡ.^

wsmrdo의 이미지

뭐 제대로 보고 하는 것은 아니지만.

int a;
char b;

b=3;
a=(int)3;

아시겠지만 이런식의 형변환 연산자가 있습니다.

새로운 변수를 할당하셔서 하셔야 할 듯 합니다.
C에서는 확실히 , 뿔난 C에게선... 그럴거다 라고 말하고 싶네요.

easyhe님이 말씀하신 부분은 하나의 이름의 함수가 인수의 형태가 달라지더라도
각각 인수의 형태대로 맞는 함수를 자동으로 찾아가는 기능을 말씀하신거 같은데.

이것과 변수자체의 형을 재정의 하는 것은 별개로 알고 있습니다.
변경 예제 에서도 제대로 동작할지 모르겠다고 한 것도 같은 맥락입니다.
(해봐야 알겠죠 ^^;;)

정확한 답변인지 모르겠습니다.
뭐 흐릿한 답이구요. 보다 자세한 것은 고수님들께서 답변해 주시길 기대해야 겠네요.

kaeri17의 이미지

FUNC2 * TypeTest::m_t = TypeTest::sampleFunc;

라는것 자체가 m_t를 정의하는 문장입니다. 근데 m_t는 이미 정의가 되었죠. 타입변경은 cast연산자를 사용하시거나 해서 타입 자체를 다른 형식으로 저장하든지 해야지 이미 선언된 변수를 다른 타입으로는 바꿀수는 없는거죠.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.