Hi all,
I am new to Linux and c++ programming.
What I am trying to do is to declare an object in a .cpp and be able to access it from main.At the moment my code creates a new object in the ena.cpp and cannot use the one from the alpha.cpp. How can i access the object from alpha.cpp (bita.dio=6) from the main (ena.cpp).
Many thanks in advance.
ena.cpp
#include <iostream>
#include "alpha.h"
#include "bita.h"
using namespace std;
int main()
{
A ob(4);
B bita;//<this creates a new project which is irrelevant of the one i need to pass from alpha.cpp
// i need to remove that
cout << ob.get_a();
cout << bita.dio;//<-- This currently outputs 2 (and not 6 as i want)
//cout << par;
return 0;
}
#include <iostream>
#include "alpha.h"
#include "bita.h"
using namespace std;
int main()
{
A ob(4);
B bita;//<this creates a new project which is irrelevant of the one i need to pass from alpha.cpp
// i need to remove that
cout << ob.get_a();
cout << bita.dio;//<-- This currently outputs 2 (and not 6 as i want)
//cout << par;
return 0;
}
To copy to clipboard, switch view to plain text mode
alpha.cpp
#include "alpha.h"
#include "bita.h"
A::A(int x)
{
B bita;
a = bita.ena;
bita.dio = 6;//<---------- i want this to be accesible by ena.cpp directly
}
int A::get_a()
{
return a;
}
#include "alpha.h"
#include "bita.h"
A::A(int x)
{
B bita;
a = bita.ena;
bita.dio = 6;//<---------- i want this to be accesible by ena.cpp directly
}
int A::get_a()
{
return a;
}
To copy to clipboard, switch view to plain text mode
alpha.h
#include "bita.h"
#ifndef ALPHA_H
#define ALPHA_H
class A {
int a;
public:
A(int x);
int get_a();
};
#endif /*ALPHA_H_*/
#include "bita.h"
#ifndef ALPHA_H
#define ALPHA_H
class A {
int a;
public:
A(int x);
int get_a();
};
#endif /*ALPHA_H_*/
To copy to clipboard, switch view to plain text mode
bita.h
#include "bita.h"
#ifndef ALPHA_H
#define ALPHA_H
class A {
int a;
public:
A(int x);
int get_a();
};
#endif /*ALPHA_H_*/
#include "bita.h"
#ifndef ALPHA_H
#define ALPHA_H
class A {
int a;
public:
A(int x);
int get_a();
};
#endif /*ALPHA_H_*/
To copy to clipboard, switch view to plain text mode
bita.cpp
#include "bita.h"
B::B(){
ena = 1;
dio = 2;
tria = 3;
}
#include "bita.h"
B::B(){
ena = 1;
dio = 2;
tria = 3;
}
To copy to clipboard, switch view to plain text mode
Bookmarks