Thread: warning C4511

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    warning C4511

    Hi,
    I am using MSVC to compile a C++ application and getting these

    warnings:
    warning C4511: 'serialCom' : copy constructor could not be generated
    warning C4512: 'serialCom' : assignment operator could not be generated

    The .h file is below. The warnings occur when I add the line std:fstream logfile;

    I have read the msdn website and I know how to turn off the warnings form being displayed but I want to know how to eliminate it. Any help would be greatly appreciated. Thanks
    Amish

    Code:
    /*
     * serialCom.h
     * This header file contains all the functions required to use the serialCom class
     *
     * Author: Amish Rughoonundon
     * Date: 19 Dec 2005
     * Version 1.0: Initial
     *
     */
    
    #pragma once
    
    #include <windows.h> /*This header contains function used only in windows*/
    #include <string>
    #include <iostream> /* iostream is used for input and output */
    #include <fstream>/* fstream is used for file accessing*/
    
    class serialCom
    {
    public:
    	/* Variables */
    
    	/* Functions */
    
    	/* 
    	 * serialCom()
    	 *
    	 * This is the constructor for the class serialCom.
    	 *
    	 * Param:  None
    	 *
    	 */
    	serialCom(void);
    
    	/* The destructor for makeSimFile Class */
    	~serialCom(void);
    
    private:
    	/* Variables */
    	std::ofstream logfile;
    	/* Functions */
    
    	/*
    	 *
    	 * This function sets up the serial serial port communication.
    	 * Baud rate: B115200 
    	 * Data size 8bit, non-parity, 1 stop bit with Hardware flow control.
    	 *
    	 * PARAM: portname:- The name of the serial port
    	 *        fd:- The handle of the serial port
    	 *
    	 * Return: Return an error code which is a negative number 
    	 *         depending on what went wrong in the function.
    	 *         Refer to Errors.info for more information
    	 *         If no errors 0 is returned.
    	 *
    	 */
    	int setupConnection(char* portname, HANDLE *fd);
    };

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Add your own copy constructor and assignment operator?

    [edit]http://www.parashift.com/c++-faq-lit...html#faq-27.10
    • A class with any of {destructor, assignment operator, copy constructor} generally needs all 3
    Last edited by Dave_Sinkula; 12-19-2005 at 08:58 PM.
    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
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Thanks for the answer although these websites I found provided more in depth information on the subject:
    http://cplus.about.com/od/beginnerct.../aa072802a.htm
    http://www.concentric.net/~rtgillam/pubs/assign.html

    Hopefully they can help other people.
    Amish

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Specifically, the problem is that std::ofstream does not have a copy constructor (how would it work with exclusively opened files?), therefore the compiler can not generate a default member-wise copy constructor for any class that contains a std::ofstream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM