473,386 Members | 1,706 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,386 software developers and data experts.

Inforrmation member funtion in C

Hi All,
Could you please anybody tell me, why c structer is not allowing funtion as the one of the member as c++ allows.

Thanks,
Sridhar.D
Jan 1 '10 #1
3 1499
Banfa
9,065 Expert Mod 8TB
Because that is one of the major differencesbetween C and C++.

C supports data structures, that is user defined types consisting of 1 or more data members.

C++ supports objects, that is user defined types that have 0 or more data members and 2 or more function members. I believe every object must have a constructor of some sort, an assignment operator, if these are not explicitly provided the compiler provides default implementations for you.

Your question is a bit like asking why does a motorcycle have 2 wheels when a car has 4? It is a defining feature of the thing in question.
Jan 1 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
However, you can have a function pointer as a struct member.

All yuo need do is assign the address of your function to the function pointer in the struct and you can do most of what C++ does.
Jan 1 '10 #3
Thanks for your reply
Jan 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: OvErboRed | last post by:
I know you can do: int (MyClass::*ptr)(int) = &MyClass::func; cout << (myObj.*ptr)(5); to point to a member function of class MyClass. But how would you go about making this generic (i.e.,...
6
by: | last post by:
Say we have the following code defining TMyMsgHandler and TMyClass typedef void (*TOnMsgReceive) (TMyMessage Msg); class TMyMsgHandler { public: TMyMsgHandler(); virtual ~TMyMsgHandler();...
5
by: Ricky Lung | last post by:
struct Foo { union { int& i; float& j; }; Foo(int& val) : i((int&)val), j((float&)val) {} };
9
by: Gernot Frisch | last post by:
class A { A(int mode) {pF = F1;} void F1() {} void (*pF)(); }; How do I do something like this? I need a function that depends on variable 'mode' and will be called
9
by: tkrogc | last post by:
I compiled the source below using the comeau compiler http://www.comeaucomputing.com/tryitout/ Why does the f funtion compile while the g function produces an lvalue error ? (I thought the two...
5
by: Lee Xuzhang | last post by:
/* from SICP -- Exercise 4.21: ((lambda (n) ((lambda (fact) (fact fact n)) (lambda (ft k) (if (= k 1) 1 (* k (ft ft (- k 1))))))) 10) */
5
by: sitha | last post by:
Hi All; I have two classes; first class, class A { // Public: void read_data1(fstream&); void write_data1(fstream&);
4
by: rammel | last post by:
Hi, I'm using a c-library in my c++ project. Therefore I've to call this c-function: int rm_init(int id, char* ip, unsigned short port, int timeout, callaback_fnc); the signatures of the...
2
by: vinothg | last post by:
Hi All, I just wanna know how compiler diffrentiates between a ordinary function and member function. I know that compiler will secretly pass the this pointer to member functions. Eg : look at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.