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. Managed C++/CLI
  4. Help me about " template"

Help me about " template"

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestionc++
3 Posts 3 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.
  • U Offline
    U Offline
    ubriela
    wrote on last edited by
    #1

    How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....

    ubri

    M H 2 Replies Last reply
    0
    • U ubriela

      How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....

      ubri

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      ubriela wrote:

      #define string char *

      Besides the fact that you are posting this in the wrong forum (this should be on the Visual C++/MFC board)... What's the error you are getting?  I can't read your code without the angle brackets on your template code... Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • U ubriela

        How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....

        ubri

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        It seems you want to use of templates but can you write fully template code and does your question on the C++/CLI?

        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