473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calling non-static member functions without an object?????

In Exceptional C++, the following code snippet appears at the bottom of page
197:

template<class T>
class Array : private ArrayBase, public Container
{
typedef Array AIType;
public:
Array( size_t startingSize = 10 )
: Container( startingSize ),
ArrayBase( Container::GetType() ),

After this code snippet, the following paragraph appears:

1. If GetType() is a static member function, or a member function that does
not use its this pointer (that is, uses no member data) and does not rely on
any side effects of construction (for example, static usage counts), then
this is merely poor style, but it will run correctly.
What am I missing here? Since when can a non-static member function ever be
called except through a concrete object? Container::GetType() is not a
valid call if GetType() is not static!!!! Surely I must be missing
something incredibly obvious here! Somebody, please set me straight!!!
Jul 22 '05 #1
1 6994
Dave wrote:
In Exceptional C++, the following code snippet appears at the bottom of page
197:

template<class T>
class Array : private ArrayBase, public Container
{
typedef Array AIType;
public:
Array( size_t startingSize = 10 )
: Container( startingSize ),
ArrayBase( Container::GetType() ),
Container::GetType() >>> this refers to the inherited Container object


After this code snippet, the following paragraph appears:

1. If GetType() is a static member function, or a member function that does
not use its this pointer (that is, uses no member data) and does not rely on
any side effects of construction (for example, static usage counts), then
this is merely poor style, but it will run correctly.
Which inherited object gets constructed first ? The ArrayBase or the
Container ? The point is that Container::GetType() gets called before
the Container object is constructed - hence the assertion that of the
undefined nature of the GetType() call. However, I'd say that the
result is plain undefined and you'd be far better off using a static
member function.



What am I missing here? Since when can a non-static member function ever be
called except through a concrete object? Container::GetType() is not a
valid call if GetType() is not static!!!! Surely I must be missing
something incredibly obvious here! Somebody, please set me straight!!!

Another example - which is what I originally thought you were thinking :

class FooBar
{
public:
void Method()
{}
};

int main()
{
FooBar * x = 0;

x->Method();
//^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined behaviour
}

Even though this is undefined, it will run quite happily on most
platforms - BUT it's really just plain wrong and it's not worth the risk
(as it is for any undefined behaviour).



Jul 22 '05 #2

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

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
6
by: komal | last post by:
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function...
1
by: Ian Sedwell | last post by:
Hi guys Many thanks to all who replied to my original question. Actually, it's dead easy and the way I was doing it was correct the first time. You do indeed simply call the VBScript routine...
2
by: Giulio Belrango | last post by:
Hi I need someones help I'm working in an IBM 390 batch environment. What I'm trying to do is to call from a non DB2 COBOL program a DB2 COBOL program that will access a table and perform an...
4
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB...
5
by: Sathyaish | last post by:
/* I am writing this C# program because I forgot the syntax for calling a parameterized constructor from a non-parameterized one within the same class. I was coding in Java and just typed it...
4
by: Jeronimo Bertran | last post by:
Hello, I have a WCF service that I am using to upload files to a server by using the streamed transfer method. I am currently calling the service from a WCF client. All I did was add a Service...
18
by: dhtml | last post by:
Array.splice({}) What should it do? I think it should return a new Array with length 0. Array.splice(arr, start, deleteCount ]]) http://bclary.com/2004/11/07/#a-15.4.4.12 Example:
4
by: Joe, G.I. | last post by:
I didn't write ClassA, but I'm trying to inherit from ClassA through ClassB. I want to pass a string to the ClassA constructor but not sure I'm calling ClassA's constructor correctly. I get the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.