How to access a data class's private member variable from another derived class whose parent class is a friend class of
Tag : cpp , By : demize95
Date : March 29 2020, 07:55 AM
it helps some times Since you have declared struct PImpl in the private part of CDataHolder class, only friends of CDataHolder can access the same. Why don't you put a forward declaration struct PImpl in the public section or even better before the CDataHolder class?
|
Initializing a class; Instead of passing required class as argument, pass a base class of that expected class
Tag : cpp , By : techthumb
Date : March 29 2020, 07:55 AM
wish of those help This is the basis of polymorphism. Wherever you have something that expects an s_api * (i.e. a pointer to base class), you are free to pass a Tvalue * (i.e. a pointer to derived class).
|
Turning a BOUNDED std::list<class> of parameters into a type std::tuple<class,class,class> tup<classObj1,
Tag : cpp , By : nobodyzzz
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This code works correctly on clang and g++ (using C++11): http://coliru.stacked-crooked.com/a/c8071ab447e10a31#include <tuple>
#include <type_traits>
#include <list>
#include <iostream>
#include <typeinfo>
template<std::size_t Max_N, typename List>
class list_to_tuple {
public:
using value_type = typename List::value_type;
using iterator_type = typename List::const_iterator;
using tuple_type = decltype(std::tuple_cat(
std::tuple<typename List::value_type>(),
typename list_to_tuple<Max_N-1, List>::tuple_type()
));
tuple_type operator()(const List& lst, const value_type& sentinel) {
return convert(lst.begin(), lst.end(), sentinel);
}
tuple_type convert(iterator_type begin, iterator_type end, const value_type& sentinel) const {
list_to_tuple<Max_N-1, List> remaining;
if(begin != end) {
auto current = std::make_tuple(*begin);
++begin;
return std::tuple_cat(current, remaining.convert(begin, end, sentinel));
} else {
return std::tuple_cat(std::make_tuple(sentinel), remaining.convert(begin, end, sentinel));
}
}
};
template<typename List>
class list_to_tuple<0, List> {
public:
using value_type = typename List::value_type;
using iterator_type = typename List::const_iterator;
using tuple_type = std::tuple<>;
tuple_type convert(iterator_type begin, iterator_type end, const value_type& sentinel) const {
return std::tuple<>();
}
};
int main() {
std::list<int> lst = {1, 2, 3};
list_to_tuple<5, std::list<int>> to_tup;
auto tup = to_tup(lst, 0);
std::cout << std::get<0>(tup) << std::endl;
std::cout << std::get<1>(tup) << std::endl;
std::cout << std::get<2>(tup) << std::endl;
std::cout << std::get<3>(tup) << std::endl;
std::cout << std::get<4>(tup) << std::endl;
std::cout << typeid(tup).name() << std::endl;
}
|
If an instance of class B is a member of class A, how can class B call a method of class A when a button in class B is p
Tag : java , By : user169463
Date : March 29 2020, 07:55 AM
this will help Your immediate objective is to invoke update on an instance of Controller within the actionPerformed method of an anonymously implemented ActionListener within ControlPanelOne's constructor. ControlPanelOne is composed within the constructor of an instance of Controller. Effectively, you need a circular reference from Controller to ControlPanelOne and visa versa. Here's a straight forward approach. You can check out the minimally worked out project here. public class Controller {
private Model m; //class Model not shown
private Viewer v; //class Viewer not shown
private JFrame frame;
private ControlPanelOne cpo;
private ControlPanelTwo cpt; //class ControlPanelTwo not shown
public Controller() {
m = new Model();
v = new Viewer();
frame = new JFrame();
frame.setLayeredPane(null); // Do something
cpo = new ControlPanelOne(this); // Supply self to the instance of ControlPanelOne
cpt = new ControlPanelTwo();
frame.add(cpo.getPanel());
frame.add(cpt.getPanel());
}
public void update() {
m.update();
v.update();
}
}
public class ControlPanelOne {
private JPanel panel;
private JButton button;
public ControlPanelOne(final Controller controller){
panel = new JPanel();
button = new JButton("press me");
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//do some stuff;
controller.update();
}
});
}
public Component getPanel() {
return null;
}
}
|
GroovyCastException: Cannot cast object 'class com.jcraft.jsch.ChannelExec' with class 'java.lang.Class' to class
Tag : java , By : Anthony Eden
Date : March 29 2020, 07:55 AM
like below fixes the issue I am trying to connect a linux machine and executing my shell script named as "myscript.sh". While running it, I am getting cast exception while same is working fine in Java. , The problem is here ChannelExec channelExec = (ChannelExec)
session.openChannel("exec");
ChannelExec channelExec = (ChannelExec.class);
session.openChannel("exec");
ChannelExec channelExec = (ChannelExec) session.openChannel("exec")
|