User Profile

Collapse

Profile Sidebar

Collapse
Harinezumi
Harinezumi
Joined: Feb 27 '08
Location: Budapest, Hungary
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Harinezumi
    replied to Overloading operator << for template class
    in C
    If I understand you correctly, then you declare the operator << for class Wrapper after the class declaration, and do not make it a friend to class Wrapper.
    But what if Wrapper is a class that does not provide a getter for the data for the output? In other words what if I want to output data from my Wrapper object that is private and does not have a getter?
    Is there a syntax for that as well?

    NOTE: I forgot to...
    See more | Go to post

    Leave a comment:


  • Harinezumi
    started a topic Overloading operator << for template class
    in C

    Overloading operator << for template class

    Hi,

    I programmed a template class and I would like to overload the output operator for it.

    Code:
    #include <ostream>
    
    template <typename ContainedType>
    class Wrapper()
    {
    public:
        Wrapper() {/* ... */}
        /* ... */ 
    
        template <typename U> 
        friend std::ostream& operator<< (std::ostream out, const Wrapper<U>&
    ...
    See more | Go to post

  • Harinezumi
    replied to Matrix template class
    in C
    You're right, I forgot about that kind of multiplication!


    It is a programming exercise for me. I already have the class, it just occurred to me that coding the rank of the matrix as template parameter may be a good idea, but now I see it is obviously not.
    Thanks for the posts!...
    See more | Go to post

    Leave a comment:


  • Harinezumi
    started a topic Matrix template class
    in C

    Matrix template class

    Hello,

    I created a template matrix class and some appropriate binary operators like:

    Code:
    template <typename ContainedType>
    Matrix<ContainedType> operator+ (const Matrix<ContainedType>& lhs, const Matrix<ContainedType>& rhs) 
    { ... }
    The first line of each such binary operator is a check, like:

    Code:
    assert(lhs.rows == rhs.rows &&
    ...
    See more | Go to post

  • Harinezumi
    replied to Virtual function signature problem
    in C
    OK, I understand what dominance does. What I don't get is why doesn't simple member function inheritance happen here, when it would be easier for the compiler than to guess what I wanted to do?
    In this case the compiler guesses wrong, because I want to distinguish the member functions through their signatures (which I thought was default).
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Virtual function signature problem
    in C
    OK, I never heard of this rule before. Can it be turned off somehow? It's usually great that the compiler thinks for itself, but in this case, I'd rather it didn't. I would like to change the behavior of my setter in my derived class, but not the getter. And users of that class shouldn't need to be aware of how these methods are inherited.

    Also, after looking up dominance, in all cases it said that it only applies to virtual inheritance....
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Virtual function signature problem
    in C
    Sorry, I posted the wrong compiler error.
    It actually says this:

    main.cpp: In function `int main()':
    main.cpp:32: error: no matching function for call to `D2::Data()'
    main.cpp:26: error: candidates are: virtual void D2::Data(const UserType&)
    See more | Go to post

    Leave a comment:


  • Harinezumi
    started a topic Virtual function signature problem
    in C

    Virtual function signature problem

    Hi,
    while creating a hierarchy of classes I ran into a strange problem: it seems the compiler doesn't inherit virtual functions with the same name but different signature if only one of them is overridden in a derived class.
    This is the smallest piece of code I could see the problem appear:
    Code:
    class UserType
    {
    public:
        UserType(float x) : x(x) {}
    
        float x;
    };
    
    class
    ...
    See more | Go to post

  • Harinezumi
    replied to Serialization template base class
    in C
    Thanks arnaudk, that cleared my confusion....
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Serialization template base class
    in C
    By I/O operators I mean std::istream& operator >> (std::istream&, <class>&) and std::ostream& operator << (std::ostream&, <class>&), which are non-member friend functions.

    How can a base implementation be provided for a pure virtual method?

    Thanks weaknessforcats , the Visitor pattern really is what I wanted to achieve....
    See more | Go to post

    Leave a comment:


  • Harinezumi
    started a topic Serialization template base class
    in C

    Serialization template base class

    Hello,
    I need help with the design of a serialization template base class.
    The idea is that any class derived from this template base class would only need to implement the input and output operators and a named constructor, Create().
    The code is something like this:

    Code:
    template <class SerializableClass>
    class Serializable
    {
    public:
        static SerializableClass* Unserialize(std::istream&
    ...
    See more | Go to post

  • Yes, I understand these.
    My question is that is there a way to use the "public interface - private virtual hook method" pattern in a multi-level inheritance hierarchy?
    (btw, is there a name for it?)...
    See more | Go to post

    Leave a comment:


  • The way of separating the public interface from the implementation in derived classes in the article above is great.
    However, when I started using it, a question emerged: what about multiple levels of inheritance, where the most derived class wants to call function in a middle level class?
    E.g.:

    [CODE=cpp]class A
    {
    public:
    A() {}
    void AMethod() { AMethodHook(); }
    private:...
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Problem with virtual inheritance
    in C
    Thanks, Savage, for the info! The missing piece of information was that when using virtual inheritance the most derived class needs to call the virtual base class.



    In the given example I don't use multiple inheritance, because I reduced the code to the smallest chunk the problem appears in. However, the full code does use multiple inheritance....
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Problem with virtual inheritance
    in C
    But doesn't the specified constructor of VDer do that? It does call the constructor of Base. It definitely works that way, when virtual inheritance is not involved.
    See more | Go to post

    Leave a comment:


  • Harinezumi
    replied to Problem with virtual inheritance
    in C
    If I do that, the compiler will not complain. However, why should a derived class have to initialize its indirect base? It doesn't make sense in my opinion....
    See more | Go to post

    Leave a comment:


  • Harinezumi
    started a topic Problem with virtual inheritance
    in C

    Problem with virtual inheritance

    Hi,

    I have a Base class, a class VDer that virtually inherits from it, and a Final class that inherits from VDer.
    The Base class only has a constructor which has a parameter.

    class Base {
    public:
    Base(const string& par) : par(par) {}
    private:
    string par;
    };

    class VDer : public virtual Base
    {
    public:
    VDer1(const string& par)...
    See more | Go to post

  • Thanks, that's a great article! It's a shame that textbooks still use public virtual functions......
    See more | Go to post

    Leave a comment:


  • C++ class design - a class to inherit different functionality

    Hello,

    I have a base class Base with given member variables, getters and setters, but it doesn't do much on its own. Then there are functionalities (Func) which can use this base class's member functions to achieve some complex computation.
    I would like to design this class structure in a way that a derived of Base, Derived can have added functionality with the use of Funcs, without further programming.

    Here's...
    See more | Go to post

  • Harinezumi
    replied to hash_map problem
    in C
    Thanks!
    I looked it up, and it turns out that hash_map is now in __gnu_cxx namespace (for gcc)....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...