CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Some code I don't understand

    I'm not sure if it's C++11 maybe but I just came across this line of code in a class declaration:-

    Code:
    explicit timepos_t (samplepos_t s) : int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE)) {}
    I don't remember seeing anything like that before and I don't quite understand what it is. Is it a variable? Or some kind of inline code segment? Or a class or struct maybe? It seems to have aspects of all three...
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Some code I don't understand

    Without more context, this looks like a constructor of a class timepos_t which takes a parameter of type samplepos_t and initializes a member variable called int62_t in the initiliazer list.
    Somehow strange.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Some code I don't understand

    I agree with Richard above.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Some code I don't understand

    Ah, that makes sense now I've woken up - the actual class looks like this:-

    Code:
    class timepos_t : public int62_t  {
      public:
    	timepos_t () : int62_t (false, 0) {}
    	timepos_t (TimeDomain d) : int62_t (d != AudioTime, 0) {}
    
    	/* for now (Sept2020) do not allow implicit type conversions */
    
    	explicit timepos_t (samplepos_t s) : int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE)) {}
    	explicit timepos_t (Temporal::Beats const & b) : int62_t (true, b.to_ticks()) {}
    
    	// Some more stuff...
    };

    I saw the 2 x c'tors at the top and then thought these were some weird code I hadn't seen before! Unfortunately the first explicit line crashes at run time so I'll need to figure out what's going on.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured