J
jd
The following code illustrates a problem I have been trying to get around in
c++. Can anyone explain how I can get this to work. The code compiles
fine if I leave out the lines with the comments after them.
Tnaks in advance for any help.
jd
//file test.cpp:
#include "pair.h"
#include "triple.h"
int main(){
pair y= pair(2,4);
triple z = triple (1,2,3);
pair *x= new pair(1,2);
triple *fg= new triple (4,5,6);
y.print_value();
z.print_value();
x->print_value();
fg->print_value();
return 0;
}
//file pair.h:
class pair {
private:
int x, y;
public:
pair(int first, int second){
x=first; y=second;
}
void print_value();
};
//file pair.cpp
#include <iostream>
#include "pair.h"
void pair:rint_value(){
std::cout << x << " " << y << "\n";
}
//file triple.h
#include "pair.h" //if I leave this and next line out, the program compiles
class triple {
private:
int x, y, z;
pair *mypair;// and leave this out
/* also if possible I'd like to be able to make the previous line work
without using a pointer as well as with. Now it works with neither unless
I leave out the line completely.*/
public:
triple(int first, int second, int third){
x=first; y=second; z=third;
}
void print_value();
};
//file triple.cpp
#include <iostream>
#include "triple.h"
void triple:rint_value(){
std::cout << x << " " << y << " " << z << "\n";
}
c++. Can anyone explain how I can get this to work. The code compiles
fine if I leave out the lines with the comments after them.
Tnaks in advance for any help.
jd
//file test.cpp:
#include "pair.h"
#include "triple.h"
int main(){
pair y= pair(2,4);
triple z = triple (1,2,3);
pair *x= new pair(1,2);
triple *fg= new triple (4,5,6);
y.print_value();
z.print_value();
x->print_value();
fg->print_value();
return 0;
}
//file pair.h:
class pair {
private:
int x, y;
public:
pair(int first, int second){
x=first; y=second;
}
void print_value();
};
//file pair.cpp
#include <iostream>
#include "pair.h"
void pair:rint_value(){
std::cout << x << " " << y << "\n";
}
//file triple.h
#include "pair.h" //if I leave this and next line out, the program compiles
class triple {
private:
int x, y, z;
pair *mypair;// and leave this out
/* also if possible I'd like to be able to make the previous line work
without using a pointer as well as with. Now it works with neither unless
I leave out the line completely.*/
public:
triple(int first, int second, int third){
x=first; y=second; z=third;
}
void print_value();
};
//file triple.cpp
#include <iostream>
#include "triple.h"
void triple:rint_value(){
std::cout << x << " " << y << " " << z << "\n";
}