error: 'void*' is not
Code:Sinuosity __stdcall Sinuosity::operator++(int x) { void* temp; temp->sin = this->sin; ++this->sin; return (Sinuosity)temp; }
error: 'void*' is not
Code:Sinuosity __stdcall Sinuosity::operator++(int x) { void* temp; temp->sin = this->sin; ++this->sin; return (Sinuosity)temp; }
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; ...
Thank you! Now compilo!
Not, error: base operand of '->' has non-pointer type 'Sinuosity'|
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.
This is certainly wrong as you cannot dereference a pointer to void:
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.Code:void* temp; temp->sin = this->sin;
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)