Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,303 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 784 people online right now. Registration is fast and FREE... Join Now!




public: __thiscall String::String(char const *)

 
Reply to this topicStart new topic

public: __thiscall String::String(char const *), I m facing a problem with this code

NoviceC++Programmer
3 Jan, 2009 - 09:52 PM
Post #1

New D.I.C Head
*

Joined: 28 Dec, 2008
Posts: 7

The code is as follows:

******************************Code starts***********************
cpp

// trials.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <conio.h>

using namespace std;

class String
{
char *s;
int length;
public:
String(const char *);
String();
//operator const char* const() {return s};
};
int main(int argc, _TCHAR* argv[])
{
cout << "Test line" << endl;
String const s1 = "abc";
String const s2 = "def";

getch();
//return strcmp(s1,s2);
return 0;
}

*******************************Code Ends*************************

when running this using visual studio 2005. I m getting 2 errors which i cant resolve. The errors are:

Error 2 error LNK2001: unresolved external symbol "public: __thiscall String::String(char const *)" (??0String@@QAE@PBD@Z) trials.obj


Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\trials\Debug\trials.exe 1


Please Help. Thanks in advance.

** Edit ** code.gif

User is offlineProfile CardPM
+Quote Post


no2pencil
RE: Public: __thiscall String::String(char Const *)
3 Jan, 2009 - 09:58 PM
Post #2

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
QUOTE

CODE

     String(const char *);
     String();

Where is this function defined?

** Renamed title to be descriptive of problem **
User is offlineProfile CardPM
+Quote Post

NoviceC++Programmer
RE: Public: __thiscall String::String(char Const *)
4 Jan, 2009 - 06:30 AM
Post #3

New D.I.C Head
*

Joined: 28 Dec, 2008
Posts: 7

is it necessary? Are they not defined in include<string.h>??
User is offlineProfile CardPM
+Quote Post

Bench
RE: Public: __thiscall String::String(char Const *)
4 Jan, 2009 - 07:01 AM
Post #4

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 827



Thanked: 57 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
C++ has its own standard string type (notice the lower-case s) which is defined in the <string> header within the std namespace. What makes you think that this will have any relationship to the String class that you've written?

<string.h> (or <cstring>, since string.h is deprecated) contains only C-style char array manipulation functions.

I assume you're writing your own String class as a learning exercise? (Otherwise its best to use the standard string type instead of reinventing the wheel). If so, where have you defined the two constructors which you've declared within your String class? The code you've given only declares their existence to the compiler - so if you haven't defined the constructors in full elsewhere, your compiler will have no idea what to do with them.

This post has been edited by Bench: 4 Jan, 2009 - 07:06 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 06:01PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month