클래스 템플릿의 부분특수화로 객체를 선언하면 실행시 오류가 발생합니다.

dltkddyd의 이미지

클래스의 특수화에 대한 아래 소스 컴파일은 잘 됩니다. 그런데 부분특수화 때문에 실행시 디버거가 계속 뜨는데 문제가 뭔지 아시는 분은 좀 알려주세요.

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
 
template<class targ_first, class targ_second > class SomeC {
public:
	targ_first x,y;
	targ_second* msg;
	SomeC() {
		printf("SomeC()\n");
	}
	void setXY(targ_first x, targ_first y) {
		this->x=x;
		this->y=y;
	}
	targ_first getX() {
		return x;
	}
	targ_first getY() {
		return y;
	}
	void setMsg(const targ_second* msg) {
		unsigned len=strlen(msg);
		this->msg=new targ_second[len+1];
		(this->msg)[len]=0;
		for(unsigned i=0;i<len;i++) {
			(this->msg)[i]=msg[i];
		}
	}
	targ_second* getMsg() {
		return this->msg;
	}
	~SomeC() {
		if(this->msg!=NULL) {
			delete[] (this->msg);
		}
	}
};
template<> class SomeC<char,char> {//전체 특수화
public:
	char x,y;
	char* mm;
	SomeC() {
		printf("In SomeC<char,char>\n");
	}
	void setXY(char x, char y) {
		this->x=x;
		this->y=y;
	}
	void setMM(const char* mm) {
		unsigned len=strlen(mm);
		this->mm=new char[len+1];
		(this->mm)[len]=0;
		for(unsigned i=0;i<len;i++) {
			(this->mm)[i]=mm[i];
		}
	}
	~SomeC() {
		delete[] (this->mm);
	}
};
 
template<class targ> class SomeC<char, targ> {//부분 특수화
public:
	char x,y;
	targ* nonchararr;
	unsigned length;
	SomeC() {
		printf("In SomeC<char,targ>\n");
	}
	void setXY(char x, char y) {
		this->x=x;
		this->y=y;
	}
	void setNonchararr(targ* nonchararr,unsigned len) {
		this->nonchararr=new char[len];;
		for(unsigned i=0;i<len;i++) {
			(this->nonchararr)[i]=nonchararr[i];
		}
		length=len;
	}
	void output() {
		for(unsigned i=0;i<length;i++) {
			cout<<nonchararr[i]<<endl;
		}
	}
	~SomeC() {
		delete[] (this->nonchararr);
	}
};
 
 
int main() {
	SomeC<int,char> ab;
	ab.setXY(10,20);
	ab.setMsg("Note");
	printf("(%d,%d), %s\n",ab.getX(),ab.getY(),ab.getMsg());
 
	SomeC<char,char> ac;
	ac.setXY('h','j');
	ac.setMM("setMM");
	printf("(%c,%c),    %s\n",ac.x,ac.y,ac.mm);
	//printf("(%c,%c)\n",ac.getX(),ac.getY());
 
	SomeC<char,int> ad;
	/*ad.setXY('l','m');*/
 
	return 0;
}

dltkddyd의 이미지

냉무(내용은 없다.....)

본인 맞습니다.
인증샷
우헤헤헤... 로 대신합니다.

익명 사용자의 이미지

nonchararr 초기화하세요.

dltkddyd의 이미지

냉무에요...(내용은 없다........)

본인 맞습니다.
인증샷
우헤헤헤... 로 대신합니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.