-3
typedef char TCHAR;

template <class T> class MyTemplateString
{

};
template <class T> class MyList
{

};
typedef MyTemplateString<TCHAR>         MyString;

MyList<MyString> outlist;// here it's showing compile time error

The error is:

Implicit instantiation of undefined template MyList <MyTemplateString<char>>

Works fine with GCC compiler only but does not work in LLVM-GCC compiler.

sehe
  • 374,641
  • 47
  • 450
  • 633
UPT
  • 1,490
  • 9
  • 25
  • 1
    You need semicolons after the closing braces. – Nordic Mainframe Oct 12 '11 at 11:38
  • 4
    I am pretty sure that the code as-is won't compile anywhere, since MyString is not defined at all. Please show the real code that this is about, not just a paraphrasation of what you think is important. – PlasmaHH Oct 12 '11 at 11:38
  • 2
    –1; please post the *actual*, compiling code. The above doesn’t compile in GCC. – Konrad Rudolph Oct 12 '11 at 11:39
  • Why is this tagged [objective-c]? – John Dibling Oct 12 '11 at 11:44
  • I have added the code defined MyString, I think the information I provided are sufficient and at the same time the templates are defined with the large amount of code and I don't think that posting the complete code will help anyone. – UPT Oct 12 '11 at 11:45
  • 1
    @KPT: `error: 'TCHAR' was not declared in this scope` this is still not the *actual* code. What is so hard in writing up an example, try it in both, and only post it when it really compiles in gcc but not in llvm-gcc ? – PlasmaHH Oct 12 '11 at 11:46
  • it is tagged for Objective-C because the project which is using these classes are linked with the objective c class project. – UPT Oct 12 '11 at 11:47
  • 1
    @KPT: Please read [this](http://sscce.org/) carefully, and then edit your question accordingly. – Björn Pollex Oct 12 '11 at 11:49
  • Thanks for link but now I think the example I shared is correct one and should be able to reproduce the issue. – UPT Oct 12 '11 at 11:50
  • Please let me know if anything else needed to describe the problem, sorry for the incomplete sample I posted before. – UPT Oct 12 '11 at 11:56
  • 2
    @KPT Your update doesn’t make the question much better. Now the code compiles with GCC **but it also compiles with LLVM/GCC and LLVM/clang++**. – Konrad Rudolph Oct 12 '11 at 11:59

1 Answers1

3

The code as posted above compiles fine here without any errors or warnings using both g++ and llvm-g++:

$ g++ -Wall -c template.cpp 

$ llvm-g++ -Wall -c template.cpp 

Version info:

$ g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~123/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

$ llvm-g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/llvmgcc42/llvmgcc42-2335.9~9/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --enable-llvm=/var/tmp/llvmgcc42/llvmgcc42-2335.9~9/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.9)

My guess is that your real problem lies elsewhere.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • I am using XCode 4 and in their there is no option of GCC compiler so I am compiling in LLVM-GCC and the error is coming, but when I compile the same code in XCode 3 with GCC compiler it's compiling perfectly. Is there any settings problem may cause the issue? – UPT Oct 12 '11 at 12:08
  • You can specify the compiler in your Xcode 4 project settings, but first you could just try compiling the code example from the command line as per my answer above (note that both cases above are using the relevant compilers from Xcode 4.0). – Paul R Oct 12 '11 at 12:19