Re: Requesting sample code!



Guido Franzke <guidof73@xxxxxxxx> wrote:
I think, if you declare a struct this way:

typedef struct strMystr
{
int m_i1, m_i2;
int get_values(int& i1, int& i2);
} SMystr;

then a constructor is not made automatically by the compiler (?).

Technically it is. But since it's a trivial constructor and doesn't do
anything, you might not find any traces of it in the generated machine
code.

class SMystr
{
public: // a public class
int m_i1, m_i2;
int get_values(int& i1, int& i2);
};

But in a class like here the compiler generates default
constructor,destructor,operator=.
I don't know exactly what happens with structs.

The same thing.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: strange compiler message
    ... >> int main ... strcpy(blah, " blah blah "); ... When I use the wrong signature the compiler issues the following error: ... All of this because C++ introduces the concept of calling a constructor ...
    (comp.lang.cpp)
  • Re: Working with strings in c++
    ... int i; ... The use of a copy constructor to initialise myStr from the temporary ... compiler to do it the two-step way, or the compiler is allowed to refuse to ... explicit MyString(const char* arg) ...
    (microsoft.public.vc.language)
  • Re: Effeciency
    ... As lame as his class is, the compiler ... > distinguish between my class and an int. ... the presence of the constructor from unsinged int means ... check with an actual integral type (via a typedef) for your release mode ...
    (comp.lang.cpp)
  • Re: operator function
    ... Well I guess you are talking about a copy constructor right? ... The compiler is talking about the result of the addition, ... an int. ... > operator returns a Setting object. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)