Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post Posted: October 19th, 2017, 8:16 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2828
Location: Oklahoma, United States
Actually, according the guidelines, you would in fact use class with public access to create an interface...huh.

Interface class

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: October 19th, 2017, 8:23 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2828
Location: Oklahoma, United States
Lol, then go and fuck it up in the next section:

Code:
struct Device {
    virtual void write(span<const char> outbuf) = 0;
    virtual void read(span<char> inbuf) = 0;
};

class D1 : public Device {
    // ... data ...

    void write(span<const char> outbuf) override;
    void read(span<char> inbuf) override;
};

class D2 : public Device {
    // ... different data ...

    void write(span<const char> outbuf) override;
    void read(span<char> inbuf) override;
};


Could just be another oversight I suppose.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: October 19th, 2017, 8:28 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2828
Location: Oklahoma, United States
Hey, found a guideline that I can agree with

Virtual functions should specify exactly one of virtual, override or final

Basically, base class should be the only one to have the virtual in front of the functions while derived classes should either have override or final appended to the function signature.

Putting virtual on derived functions to me made it seem like there were going to be derived classes from the derived class ( grandchildren ). I never liked it, it confused me. I like specifying override letting me know it overrides a virtual function and haven't used final yet, but I guess I should start.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: October 19th, 2017, 8:51 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2828
Location: Oklahoma, United States
Man, one could spend hours correcting the guideline document.

The PImpl idiom
Code:
class widget {
    class impl;
    std::unique_ptr<impl> pimpl;
public:
    void draw(); // public API that will be forwarded to the implementation
    widget(int); // defined in the implementation file
    ~widget();   // defined in the implementation file, where impl is a complete type
    widget(widget&&) = default;
    widget(const widget&) = delete;
    widget& operator=(widget&&); // defined in the implementation file
    widget& operator=(const widget&) = delete;
};


Here the private data is listed first before the public interface.

This seems a lot like how people feel about the bible with all sorts of contradictions.

Another thing I find weird is unique_ptr not complaining about using a forward declared class.
I get the message:
Error C2027 use of undefined type 'Stub::Impl' testbed2 f:\program files (x86)\microsoft visual studio 14.0\vc\include\memory 1193
Code:
stub.h
class Stub
{
public:
   Stub(std::string Msg);

   void PrintMsg();
private:
   class Impl;
   std::unique_ptr<Impl> pImpl;
};

stub.cpp
class Stub::Impl
{
public:
   Impl( std::string Msg );
   void PrintMsg()const;
private:
   std::string msg;
};

Stub::Stub( std::string Msg )
   :
   pImpl( std::make_unique<Impl>( std::move( Msg ) ) )
{}

void Stub::PrintMsg()
{
   pImpl->PrintMsg();
}

Stub::Impl::Impl( std::string Msg )
   :
   msg( std::move( Msg ) )
{}

void Stub::Impl::PrintMsg() const
{
   std::cout << msg << std::endl;
}

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: