![]() |
|
#1
|
|||
|
|||
"cannot convert from 'class X *' to 'class X'" ??What's the problem here? when i try to create a new instance of my class Signature it's giving me the following error:
c:\PredicateLogicTrainer\signature.h(104) : error C2440: 'initializing' : cannot convert from 'class Signature *' to 'class Signature' No constructor could take the source type, or constructor overload resolution was ambiguous Error executing cl.exe. main.exe - 1 error(s), 0 warning(s) it refers to the following line: CPP / C++ / C Code:
I'm lost... is this the right way to create a class?? Here's the full code: CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
|
in C++, the "new" keyword is used to create pointers as far as I know, so maybe you should do:
Code:
Code:
|
|
#3
|
|||
|
|||
|
Quote:
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
|
Quote:
Thanks buddy, You're a star!! I've got other errors now, but that one was killing me. Cheers! |
|
#5
|
|||
|
|||
|
Now, the above works!!
However, in the main file, I want to create a signature... so naturally i type: CPP / C++ / C Code:
but i get the following error: Linking... main.obj : error LNK2001: unresolved external symbol "public: __thiscall Signature::Signature(void)" (??0Signature@@QAE@XZ) main.obj : error LNK2001: unresolved external symbol "public: __thiscall Signature::Signature(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class st d::allocator<char> > * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const)" (??0Signature@@QAE@V?$basi c_string@DU?$char_traits@D@std@@V?$allocator@D@2@@ std@@QAV12@11@Z) Debug/main.exe : fatal error LNK1120: 2 unresolved externals Error executing link.exe. Note, this is not a compile error, it's a linking error.... i don't have a clue what that is... |
|
#6
|
|||
|
|||
|
I believe it's the linker's way of saying, "Hey, buddy! You told me to expect these:"
CPP / C++ / C Code:
In other words, you need to define these functions. Mere declarations are not enough. Otherwise every one of us would have written this, run it, and quit coding to retire on some beach: CPP / C++ / C Code:
|
|
#7
|
||||
|
||||
|
Quote:
For the linker problem though, I agree with Dave. Do something like this for each undefined function: CPP / C++ / C Code:
Quote:
CPP / C++ / C Code:
there we go |
|
#8
|
|||
|
|||
got this to workthis compiles, links and executes...
I agree, you have no member function bodies, unless you have them in a seperate header file? CPP / C++ / C Code:
OR, quick edit, I prefer this one... Up2U. CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
|
Hopefully what was posted is not actually in a header. If so, I'd recommend to the OP to quit now and learn how it's supposed to be done -- no code in headers! (With exceptions for templates at least.)
And no using namespace std; in headers either! |
|
#10
|
|||
|
|||
Dave, I agree...All classes should have a header file of the class definition and a cpp source file that contains the code. This is how I solved it, but I put it back as it was originally, roughly, posted. Also, avoid the namespace issue of name clashing, such as std::count.
|
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Introduction to .NET | LuciWiz | .NET Forum | 5 | 09-Aug-2007 04:53 |
| Opinion on my code and a c++ class question | FlipNode | C++ Forum | 7 | 07-Feb-2006 08:15 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | C++ Forum | 2 | 19-Dec-2004 06:06 |
| hashing help | saiz66 | C++ Forum | 1 | 06-Jul-2004 06:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The