i just started working on structures and i am having this problem:
i created a structure "point" thus :

struct point
{ 
 double x,y;
};

i created another structure "rectangle" that contains a point as the origin like this:

struct rectangle { 
  point origin; 
  double width, height; 
};

in the function main, i created a rectangle carton like this :
point origin={0,0};
rectangle carton={origin,20,60};
but the compiler was telling me that :
error C2440: 'initializing' : cannot convert from 'struct point' to 'double'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
but when i created a rectangle like this:
rectangle carton={{0,0,},0,0};
there was no problem, the program run fine
This is the whole source code :
// program test the behavior of structures

#include <iostream>
using std::cout;
using std::endl;
struct point
{ 
 double x,y;
};
struct rectangle { 
  point origin; 
  double width, height; 
};//declaration of a structure rectangle
void swapReference(point& slave){
 double temp = slave.x;
 slave.x = slave.y;
 slave.y = temp;
}//functions(with ampersand & in parameter)  affects the point in question
//for example to reduce the size from main function
void swapValue(point slave){
 double temp = slave.x;
 slave.x = slave.y;
 slave.y = temp;
}//Functions (with no ampersand & in parameter)  wont affect the initial point used as arguement
//for example if you want to make requests from the point like 
void printPoint(point slave){
 cout<<slave.x<<" "<<slave.y<<endl;
}// function to print the point
rectangle increaseSize(rectangle& box,double width,double height){
 box.width += width;
 box.height += height;
 return box;
}
void printRectangle(rectangle box){
 cout<<"\nWidth : "<<box.width<<" height : "<<box.height<<endl;
}
int main(){
 //playing with points
 //declaration of variables
 point highest={ 84, 100};
 swapValue(highest);
 printPoint(highest);
 swapReference(highest);
 printPoint(highest);
 //playing with rectangles
 //declaration of variable
 point origin={0,0};
 rectangle carton={origin,20,60};
 increaseSize(carton, 100, 20);
 printRectangle(carton);
 return 0;
}
Member Avatar for GreenDay2001

Works perfect in my compiler Visual C++ 2005 Express, which compiler do you use.

my compiler is Microsoft Visual C++ 6.0

thnx alot,
i really appreciate your concern;

my compiler is Microsoft Visual C++ 6.0
i dont even know whether its the compiler cos i have been having problems with my classes too... check the lounge you will see...

did the program work when you replace

rectangle carton={{0,0},0,0};

with

point origin={0,0};
rectangle carton={origin,0,0};

cos that is where i get my problem;

Member Avatar for GreenDay2001

thnx alot,
i really appreciate your concern;

my compiler is Microsoft Visual C++ 6.0
i dont even know whether its the compiler cos i have been having problems with my classes too... check the lounge you will see...

did the program work when you replace

rectangle carton={{0,0},0,0};

with

point origin={0,0};
rectangle carton={origin,0,0};

cos that is where i get my problem;

Yes that works.
Visual C++ 6.0 is quite old and quite buggy too. So get a new compiler, maybe that helps you:
These all are good and free:

Visual C++ 2005 Express Edition
CodeBlocks IDE
Turbo C++ 2006 (not that old one, www.turboexplorer.com )
Dev C++

hey, thanx
i am now downloading one of the compilers, how do i flag that this problem has been solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.