Thread: As it is right?

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    112

    As it is right?

    error: 'void*' is not

    Code:
    Sinuosity __stdcall Sinuosity::operator++(int x)
     {
        void* temp;
        temp->sin = this->sin;
        ++this->sin;
        return (Sinuosity)temp;
    }

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    void pointers are more or less meant for raw byte allocations. If you wanna use temp, you need it to point to a real type. Keep in, void pointers are allowed but there's no such thing as a void value in C++. So your code should be,
    Code:
    Sinuosity temp;
    ...

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    112
    Thank you! Now compilo!

  4. #4
    Registered User
    Join Date
    Nov 2015
    Posts
    112
    Not, error: base operand of '->' has non-pointer type 'Sinuosity'|

  5. #5
    Registered User
    Join Date
    Nov 2015
    Posts
    112
    Code:
    Sinuosity* temp;
    
    
    warning: extra qualification 'Sinuosity::' on member 'operator++' [-fpermissive]|
    In member function 'Sinuosity Sinuosity::operator++(int)':|
    error: no matching function for call to 'Sinuosity::Sinuosity(Sinuosity*&)'|
    note: candidates are:|
    note: Sinuosity::Sinuosity()|
    note:   candidate expects 0 arguments, 1 provided|
    note: constexpr Sinuosity::Sinuosity(const Sinuosity&)|
    note:   no known conversion for argument 1 from 'Sinuosity*' to 'const Sinuosity&'|
    warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 6 second(s)) ===|
    Last edited by Dmy; 04-18-2017 at 03:12 PM.

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    We might need to see the full code here.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,152
    This is certainly wrong as you cannot dereference a pointer to void:
    Code:
    void* temp;
    temp->sin = this->sin;
    Hence MutantJohn suggested that you create an object of the class type, but it looks like you then forgot to adjust the corresponding code, e.g., from temp->sin to temp.sin. Then you tried creating a pointer to an object of the class type, but of course that is insufficient since you do need a copy of the current object, not merely a pointer.

    Generally, if you are implementing the postfix version of operator++ for some type T such that it has the usual semantics, you can simplify by implementing it in terms of its prefix operator++, i.e.,
    Code:
    T T::operator++(int x)
    {
        T temp(*this);
        ++*this;
        return temp;
    }
    Last edited by laserlight; 04-20-2017 at 06:18 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Tags for this Thread