Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. template class Problem

template class Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionwpflearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mehran Ziadloo
    wrote on last edited by
    #1

    What a perfect world it could be with out errors. Going forth in a software developement I got to an error which I could not find a resource that give an answer. It's about templates, and I must tell you that I'm new in this stuff. Consider 'ClassA' which requiers template list when you want to define a object of it. Like this: ClassA<long> obj; And Consider another class that is the same to the previous one, 'ClassB' (with template list). Now here's the problem, how can you define an object of 'ClassA' with the template list of 'ClassB' type, it should be something like this: ClassA<ClassB> obj; But compiler tells me that it has an error becuase 'ClassB' requiers a list of templates. So I thought that it might be defined like this: ClassA<ClassB<long>> obj; Now it has an another error: error C2146: syntax error : missing ',' before identifier 'obj' Well how can I define an object from a class with template list of sort of a class with template list?

    P 1 Reply Last reply
    0
    • M Mehran Ziadloo

      What a perfect world it could be with out errors. Going forth in a software developement I got to an error which I could not find a resource that give an answer. It's about templates, and I must tell you that I'm new in this stuff. Consider 'ClassA' which requiers template list when you want to define a object of it. Like this: ClassA<long> obj; And Consider another class that is the same to the previous one, 'ClassB' (with template list). Now here's the problem, how can you define an object of 'ClassA' with the template list of 'ClassB' type, it should be something like this: ClassA<ClassB> obj; But compiler tells me that it has an error becuase 'ClassB' requiers a list of templates. So I thought that it might be defined like this: ClassA<ClassB<long>> obj; Now it has an another error: error C2146: syntax error : missing ',' before identifier 'obj' Well how can I define an object from a class with template list of sort of a class with template list?

      P Offline
      P Offline
      Per Nilsson
      wrote on last edited by
      #2

      Hi The solution is pretty simple. In stead of ClassA> obj; use ClassA > obj; Yes, the only difference is a space. The reason for the error is that the compiler finds '>>' and believes it to be the >> operator instead of the end of the template lists. So if you put in a space, the first > will end the inner template list and the second the outer and the compiler is happy.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups