Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Can't compile source code with string [SOLVED]

    SDK Help
    0
    10
    738
    Loading More Posts
    • 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.
    • H
      Helper
      last edited by

      On 05/09/2014 at 14:09, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   14 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      I have, in my code, variables of type String and variables of type string.
      I'm using some std:: stuff so I must use string instead of String.
      It compiles and works fine on my Mac.
      But while trying to compile it in Windows, I get lots of errors and the compilation fails.
      Is there anything that can be done?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 05/09/2014 at 16:49, xxxxxxxx wrote:

        Why does it compile without a single complain in Xcode and, in Visual Studio I get dozens of errors?!?

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 05/09/2014 at 18:39, xxxxxxxx wrote:

          Are you making string explicit to the std library by using std::string for references?

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 05/09/2014 at 18:46, xxxxxxxx wrote:

            I don't know what you mean.
            Can you give me an example?

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 05/09/2014 at 18:52, xxxxxxxx wrote:

              std is a namespace.  You can declare the namespace for referencing objects in that space explicitly (std::space) or implicitly (using namespace std) somewhere at the top of the file.  Which to use will depend on if there are possible clashes.  Let's say you have a string type in std and another in another namespace included in your code.  If they are not explicitly declared, there is a chance that the compiler doesn't understand which one to use.  If you are just using 'string', you must add 'using namespace std'.

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 06/09/2014 at 14:54, xxxxxxxx wrote:

                Thank you so much, Robert.
                What was happening was the I had these two lines:

                  
                template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }   
                using namespace std;   
                

                and I simply had to switch them, like this:

                  
                using namespace std;   
                template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }   
                

                The correct way is the second, of course. But it is weird that Xcode doesn't complain and makes it work, somehow.

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 06/09/2014 at 15:59, xxxxxxxx wrote:

                  Technically, you can declare 'using namespace' anywhere in the global scope of the source code.  You can do this with '#include" for headers as well.  It is generally safer to do these first nonetheless.  And you want to declare the namespace after any header that defines it (!).

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 07/09/2014 at 09:29, xxxxxxxx wrote:

                    All what Kuroyume wrote. However, I would encourage you to not use "using namespace x" but instead use x::function. This avoids any library conflicts.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 07/09/2014 at 12:28, xxxxxxxx wrote:

                      Agreed! 🙂

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 07/09/2014 at 12:56, xxxxxxxx wrote:

                        Thank you all. I will take that into account in the future.
                        In the meanwhile, I could make it all work now.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post