Answers:
structures do not contain functions and constructor is a special function.hence,structures can't contain constructors
 Posted by: pramila
Contact pramila
answer is completely wrong. see structure behaves diffrently depending on c or c++ language 1>if ur in c++ then u can write function as a part of structure . 2> but if ur in c programming then u cannot write functions as a part of structure. see following code for c++( keep file name with cpp (filaname.cpp)format. then try this code #include <stdio.h> #include <conio.h> #include <iostream.h> struct A { public: int a; public: A set_A(A a); }; A set_A(A a1) { a1.a=10; return a1; } int main() { A var,ret; var.a=0; ret=set_A(var); cout<<" Return value is:-"<<ret.a; return 0; } repeate same thing by just renaming that file as filename.c & try it out u can easily find difference.
 Posted by: Amit saraf
Contact Amit saraf
There is two basic difference between struct in C and C++: 1> Structures in C++ are similar to Classes in C++ only that by default the access specifier in structure is public whereas in Classes it is private. 2> While declaring a instance of a struct you can just use the name of the structure, and you don't need to qualify it with the keyword struct. STRUCTURES IN C++ File:- abc.h #ifndef ABC_H #define ABC_H struct abc { abc(); }; #endif File:- abc.cpp #include "abc.h" #include <iostream.h> abc::abc() { cout<<"Structure Constructor"<<endl; } File:- MainFile.cpp #include<iostream.h> #include"abc.h" int main() { abc *a = new abc(); return 0; }
 Posted by: Sandipan Karmakar
Contact Sandipan Karmakar
struct Test { Test() { cout<<"Object Created Successfully"; } }; int main() { Test ob; return 1; }
 Posted by: Bhattad Jeetendra
Contact Bhattad Jeetendra
If you have the better answer, then send it to us. We will display your answer after the approval.