Thread: A few beginner's questions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    1) Yes, you use public: and list everything
    2) You shouldn't get an error. You can define the method in a normal class. There are some issues though. Does that method (function) uses objects from another class? If so you have to check forward declaration and stuff which don't exist (hopefully) in C#. In any case it won't be defined globally, you would probably need the :: scope symbol. Like class::method. Post certain code for more clarifications.
    4) In C++ this is an object:
    Code:
    object O;
    the same way you declare a variable. You can use a constructor like:
    Code:
    object O(a,  b);
    the new keyword dynamically allocates memory.
    In C# this is a reference and not an object:
    Code:
    object O;
    the equivalent thing in C++ is this for a reference:
    Code:
    object& O; //even though you would get an initialization error
    Code:
    object& O = new Object(a,b);
    So, the new is dynamically allocation, without the new is statical allocation. In any way you will have allocated memory.
    5) There should be certain functions that do that. I ll search and post some

    A C++ way is:
    Code:
    std::stringstream ss;
    int t = 123;
    ss << t;
    std::string str = ss.str();
    The opposite:
    Code:
    std::istringstream ss;
    std::string str = "2443"
    int t;
    ss >> t;
    You can also use sprintf(), atoi() and other functions. Google and you will find many results.

    For example I find this:
    Code:
    #include <boost/lexical_cast.hpp>
    #include <string>
    
    try
    {
        std::string text = "152";
        int number = boost::lexical_cast< int >( text );
    }
    catch( const boost::bad_lexical_cast & )
    {
        //unable to convert
    }
    Last edited by C_ntua; 10-21-2008 at 05:21 AM.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    To make my point more clear about your 4) questions.
    In C# ALL objects go in the heap. They are dynamically allocated.
    In C++ you choose where objects go. If you declare them "normally" the go in the stack. If you use the new keyword the go in the heap (dynamically allocated). C++ does things as they would normally be done in C.

    In C# you have the option of statically allocating or dynamically allocating when you use value types, like int, uint, char etc etc not reference types, like objects.

    This might help: http://www.c-sharpcorner.com/UploadF...5-413b6d348b91

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner's Questions
    By bjl in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2008, 06:56 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM