C++ binary code vs. source code 
Author Message
 C++ binary code vs. source code

I am always confused by the mechanism of C++ when code is compiled into
binary form or stays in source code from. If a class A is compiled without a
copy constructor and with only its compiled code(and .h file), if the user
defines a copy constructor, will the binary code call the newly-defined the
copy constructor when assigning and so on?
                            Thanks for informatin.


Sun, 30 Dec 2001 03:00:00 GMT  
 C++ binary code vs. source code

Quote:

> I am always confused by the mechanism of C++ when code is compiled into
> binary form or stays in source code from. If a class A is compiled without a
> copy constructor and with only its compiled code(and .h file), if the user
> defines a copy constructor, will the binary code call the newly-defined the
> copy constructor when assigning and so on?
>                             Thanks for informatin.

Simon,

You cannot add a member function that is not declared inside the class
declaration. Something like:
//A.h
class A
{
public:
  void func1();

Quote:
};

//in a different file
#include "A.h"

A::A(const A&) //error; definition of a member function that is not
declared in its class
{
//...

Quote:
}

results in a compilation error.

If you don't declare a special member function explicitly, the compiler
implicitly declares it and under certain circumstances, it also
generates code for it. The generated special member functions (ctor,
copy ctor, assignment op and destructor) are expanded inline.

Danny Kalev

"The ANSI/ISO C++ Professional Programmer's Handbook"
http://www.amazon.com/exec/obidos/ASIN/0789720221



Sun, 30 Dec 2001 03:00:00 GMT  
 C++ binary code vs. source code
Quote:
> You cannot add a member function that is not declared inside the class
> declaration. Something like:
> file://A.h
> class A
> {
> public:
>   void func1();
> };

> file://in a different file
> #include "A.h"

> A::A(const A&) file://error; definition of a member function that is not
> declared in its class
> {
> //...
> }

> results in a compilation error.

> If you don't declare a special member function explicitly, the compiler
> implicitly declares it and under certain circumstances, it also
> generates code for it. The generated special member functions (ctor,
> copy ctor, assignment op and destructor) are expanded inline.

> Danny Kalev

> "The ANSI/ISO C++ Professional Programmer's Handbook"
> http://www.amazon.com/exec/obidos/ASIN/0789720221

Danny Kalev:
   Thanks for the information above
  But what if the user modify the supplied header file to make a copy
constructor  a member of the class?
  The question can better be expressed like this:
   Is the copy constructor virtual or not? This means whether the user can
modify the copy constructor's behaviour in a binary form of C++ class.


Mon, 31 Dec 2001 03:00:00 GMT  
 C++ binary code vs. source code

Quote:
>    Thanks for the information above
>   But what if the user modify the supplied header file to make a copy
> constructor  a member of the class?

And what if the user will change a constant like:
#define    TRUE    1
to
#define    TRUE    0

This question is meaningless.

Quote:
>   The question can better be expressed like this:
>    Is the copy constructor virtual or not? This means whether the user can
> modify the copy constructor's behaviour in a binary form of C++ class.

No constructor is virtual, it doesn't make sence. If you want to allow users
to override the code in copy constructor, do 2 phase construction. One will
be your default constructor and the other will be some virtual function like
Init(...).

--

Jan Bares
(remove no.spam from my email address)
JPCAD Graphics Engine developer, surf to http://www.antek.cz
PGP ID: 0x6BFE492A



Mon, 31 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to convert source code pascal to source code c

2. Java source code to CSharp source code converter

3. entering binary numbers in source code

4. Binary Search Tree Source Code?

5. Binary Tree Source Code...

6. Any binary editor w/ source code available

7. Debug Binary -> Source Code

8. How to compile Visual C++ 1.0 source code using Visual C++ 4.0

9. Calling C++ from C/Linking (was: C++ code to C Code)

10. managed code vs. non-managed code

11. New C# Source Code Sample - Running JScript.NET Code from C# Apps

12. Back to VS.Net beta2, there was a code share plugin featured browsing code from Internet

 

 
Powered by phpBB® Forum Software