473,769 Members | 5,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Miranda functions and Initialization


Is this them all?:
class Dummy
{
public:

Dummy() {}

Dummy(const Dummy& original) { }

Dummy& operator=(const Dummy& lhs) {}

const Dummy * operator&() const { return this; }

Dummy * operator&() { return this; }

~Dummy() {}

};
Also could anyone please inform me of circumstances in which these are
edited and in which they disappear? For example I'm already aware of the
following:

1) Dummy() disappears if you supply another one that takes arguments, eg.
Dummy(int).

2) operator= and the copy constructor will change for every extra member
variable that's added to the class.
--

Now, take the following:

int main()
{
int j;
}
I'm fully aware that j contains no particular value, it hasn't been
initialized.

Now take the following:

int main()
{
int j = 45;
}

I'm fully aware that that's equal to:

int j = int(45);

But, where you have user-defined types, what exactly goes on?

For instance:

SomeClass k = 78.222;
Does that become:

SomeClass k = SomeClass(78.22 2);

And then is the SomeClass(const SomeClass&) copy constructor called? Or...
does the compiler simply look for a different copy constructor, eg.
SomeClass(const double&)? Or is that even valid?

Anyway here's what I'm getting at: I know int() is equal to zero, ie. if you
specify brackets then it gets intialized to zero. Now ofcourse you have the
problem of:

int main()
{
int j();
}

The compiler doesn't know if it's an object definition or a function
declaration (...if only "extern" was compulsory). As such, it assumes a
function declaration.

Is the only way to get around this to write:

int j(0);

?

Anyway here comes my question:

class Chocolate
{
public:

int a;

double b;

};
int main()
{
Chocolate choco;
}
Do "a" and "b" get initialized to zero? And if so, what does it? Is it the
miranda default constructor? What about in the following code:

class Chocolate
{
public:

int a;

double b;

Chocolate() {}

};
int main()
{
Chocolate choco;
}
Do "a" and "b" get initialized to zero in the above?
-JKop
Jul 22 '05
21 2025
JKop wrote:
[snip] There's just one thing that I want to figure out:

SomeClass object = SomeClass();

There has to be some sort of way of turning the following:

SomeClass object();

into an object definition. I've tried:

class SomeClass object();
struct SomeClass object();

But still they're a function declaration. That doesn't make sense to me.
That's because there are circumstances (don't remember which exactly) where
the compiler cannot differentaiate between a function declaration and an
object definition.
That's why there is the rule: If it lools like a function declaration, it
is a function declaration.

There is nothing you can do about it.
class SomeClass object();


object is a function which returns a class SomeClass object.
That's the way it is.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #21
Karl Heinz Buchegger posted:
JKop wrote:
[snip]
There's just one thing that I want to figure out:

SomeClass object = SomeClass();

There has to be some sort of way of turning the following:
SomeClass object();

into an object definition. I've tried:

class SomeClass object();
struct SomeClass object();

But still they're a function declaration. That doesn't make sense to me.


That's because there are circumstances (don't remember

which exactly) where the compiler cannot differentaiate between a function declaration and an object definition.
That's why there is the rule: If it lools like a function declaration, it is a function declaration.

There is nothing you can do about it.
class SomeClass object();
object is a function which returns a class SomeClass

object. That's the way it is.


I asked this question on comp.std.c++, but it seems the
asshole, opps I mean the moderator, didn't feel it was fit
for posting.
-JKop
Jul 22 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2552
by: Robert Allan Schwartz | last post by:
I've heard the phrase "Miranda function" used to refer to the 6 member functions supplied by the compiler: default constructor copy constructor destructor operator= operator& const operator&
4
1433
by: ypjofficial | last post by:
Pls look at this code ////////////////////start/////////// class a { public: a(){ cout<<"inside constructor of a"<<endl; } int b()
10
1551
by: smreddy | last post by:
Is it possible to call a C++ function in C program ? if so ? Regards Srinath
687
23732
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
9
2634
by: Gibby Koldenhof | last post by:
Hiya, Terrible subject but I haven't got a better term at the moment. I've been building up my own library of functionality (all nice conforming ISO C) for over 6 years and decided to adopt a more OO approach to fit my needs. Altough I used an OO approach previously for some subparts of the library it became somewhat difficult to maintain all those parts since they really are the same thing coded for each part (code duplication). So...
15
2078
by: roberts.noah | last post by:
I ran across some code that called memset(this, 0, sizeof(*this)) in the member function of a structure in C++. This just looked wrong to me so I did some web searching and it does indeed seem like a questionable thing to do. Looking around further took me to a newsgroup discussion that said the better approach was to do something like sv = Struct(). The thing is that both cases seem to bo "ok" so long as there are no virtual functions...
2
1288
by: red floyd | last post by:
Someone asked me about the construct below: class Base { public: // all other elements redacted Base& operator=(const Base&); }; class Derived : public Base { public:
8
8931
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
17
3547
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;" instead? I think declaring a function as "=0" is the same
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.