Constructor not being called.

This is a discussion on Constructor not being called. within the C++ Programming forums, part of the General Programming Boards category; When I call my constructor, nothing seems to happen I'm getting this error message: warning C4930: 'String something(void)': prototyped function ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Constructor not being called.

    When I call my constructor, nothing seems to happen I'm getting this error message:

    warning C4930: 'String something(void)': prototyped function not called (was a variable definition intended?)

    Heres what I have so far of my class:
    Code:
    typedef unsigned char Uint8;
    typedef unsigned short Uint16;
    typedef unsigned int Uint32;
    
    class String
    {	
    	public:
    		String();
    		String(const char *);
    		~String();
    		int Len(char *str);
    		void StrCat(char *str, char *add);
    		void PrintString();
    		void SetString(char *str);
    		
    	private:
    		Uint16 size;
    		char *str_ptr;
    };
    
    String::String()
    {
    	size = 1;
    	str_ptr = new char[size];
    	*str_ptr = '\0';
    	cout << size << "\nSay something!";
    }
    And heres where I'm making a new string object:
    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	String something();
    	return 0;
    }
    Can someone tell me why nothing seems to happen? I'm sure it must be something really simple. Cheers.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by mike_g View Post
    And heres where I'm making a new string object:
    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	String something();
    	return 0;
    }
    Can someone tell me why nothing seems to happen? I'm sure it must be something really simple.
    That's not an object being default constructed, that's a function prototype.
    http://www.parashift.com/c++-faq-lit....html#faq-10.2
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I originally did it without the brackets, but then I got this error:
    fatal error LNK1120: 1 unresolved externals
    Which made even less sense to me I had a play around with it today, and I found that I needed to put a couple of braces after my destructor. So yeah, it works now thanks

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by mike_g View Post
    I originally did it without the brackets, but then I got this error:
    fatal error LNK1120: 1 unresolved externals
    Which made even less sense to me I had a play around with it today, and I found that I needed to put a couple of braces after my destructor. So yeah, it works now thanks
    Perhaps that is because you told the build chain that you were going to write a destructor, among other functions:
    Code:
    		~String();
    But you never actually provided them like you promised.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    yeah, that would be it. I'll learn to understand the error messages someday

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Destructor being called on SGI hash_map key
    By cunnus88 in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2009, 12:05 AM
  2. Replies: 4
    Last Post: 09-21-2008, 03:27 PM
  3. callback from exe called with system()
    By leonv in forum C Programming
    Replies: 3
    Last Post: 01-25-2008, 04:12 PM
  4. AAARG!!! mental block, what is this character called: ')'
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-29-2002, 10:29 PM
  5. Program ive been working on called ChatMate
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-23-2002, 09:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21