twitchyliquid64 Posted April 17, 2012 Share Posted April 17, 2012 (edited) Hi all, Im building a variant class that I want to make work, but Im running into compiler issues; issues that highlight that I have no idea what is going on under the hood for operators in C++. My class looks something like: class Variant { public: //Constructors Variant(void) : type(VAR_INTTYPE), int64value(0), databuffsize(0), databuff((char*)0) {} Variant(int); Variant(long long); Variant(double); Variant(const char* in); Variant(char* in); Variant(Variant & in);//Copy Constructor ~Variant();//Destructor //Operators Variant& operator= (Variant&); Variant& operator= (Variant); //Other irrelvant code... } And Im trying to do things like: Variant test; int main() { test = Variant(20); //btw, I have no intention of implementing assignment ops for primitive types for various reasons Variant lol(7); lol = test; return 0; } In GCC (mingw) this is throwing errors like: error: no matching function to call for 'Variant::Variant(Variant)' Any ideas what constructors or operators I am missing? I have looked around and cannot find any solution to my problem. Thanks in advance. Edited April 18, 2012 by twitchyliquid64 ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
Valik Posted April 17, 2012 Share Posted April 17, 2012 Copy constructor is not const correct. Also, did you actually implement the copy constructor or just declare it? If you did declare it in a separate file you didn't make it inline, did you? Link to comment Share on other sites More sharing options...
twitchyliquid64 Posted April 17, 2012 Author Share Posted April 17, 2012 Copy constructor is not const correct. Also, did you actually implement the copy constructor or just declare it? If you did declare it in a separate file you didn't make it inline, did you?all the methods listed there are fully implemented in the variant.cpp file.I'm pretty sure i inlined it ... is that bad? file size isn't an issue.what do you mean by not const correct? do you mean i need a constructor with a const variant reference as the parameter? ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 17, 2012 Share Posted April 17, 2012 Copy constructor is name(const &name) Link to comment Share on other sites More sharing options...
Kip Posted April 17, 2012 Share Posted April 17, 2012 Instead of overloading the assigment operator twice: Variant& operator= (Variant&); Variant& operator= (Variant); I would do this: Variant const& operator=(const Variant&); MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 17, 2012 Share Posted April 17, 2012 (edited) Why would you force a const return? What if I wanted to do something like (a = .change()? Edited April 17, 2012 by Richard Robertson Link to comment Share on other sites More sharing options...
Valik Posted April 17, 2012 Share Posted April 17, 2012 If you inline a function in a CPP file then it cannot be seen outside that CPP file. It must either be inlined in the header file or you must remove the inline flag in the CPP file. Link to comment Share on other sites More sharing options...
twitchyliquid64 Posted April 18, 2012 Author Share Posted April 18, 2012 Thanks everyone for your help. In the end the problem was that my copy constructor needed to accept a const reference rather than just a reference. ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 19, 2012 Share Posted April 19, 2012 Copy constructor is name(const &name) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now