[SOLVED] C++ :: How to get two separate classes to talk to each other?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
/*
wmslideshow.cpp
Copyright (c) 2018 Michael Heras
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307,
USA.
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype> //isdigit
#include <X11/extensions/shape.h>
#include <Imlib2.h>
#include "wmslideshow.hpp"
#include "files.hpp"
void WMDockWindow::parseCommandLine(int argc, char **argv)
{
if (argc > 1)
{
for (int i = 1; i < argc; i++)
{
if(!strcmp(argv[i], "-f"))
{
std::string filename = argv[i+1];
if (checkIfFile(filename))
std::cout<<filename<<std::endl;
else
{
std::cerr<<"Not a valid file "<<filename<<std::endl;
exit(1);
}
i++;
}
else if (!strcmp(argv[i], "-p"))
{
std::string pathname = argv[i+1];
if (checkIfDirectory(pathname))
std::cout<<pathname<<std::endl;
else
{
std::cerr<<"Not a valid path "<<pathname<<std::endl;
exit(1);
}
i++;
}
else if (!strcmp(argv[i], "-t"))
{
if (argv[i+1] == NULL)
{
std::cerr<<"No valid input. "<<std::endl;
usage(argv);
exit(0);
}
else if ( (stime = int_or_ch(argv[i+1])) == -1 )
{
std::cerr<<"Invalid time. "<<argv[i+1]<<std::endl;
exit(1);
}
i++;
}
else if (!strcmp(argv[i], "-r"))
{
setRandom = 1;
i++;
}
else if (!strcmp(argv[i], "-o"))
{
setOrdered = 1;
i++;
}
else
{
std::cerr<<APPNAME<<" :Invalid option. -> "<<argv[i]<<std::endl;
usage(argv);
}
}//end for parse
}//end if argc
}
WMDockWindow::WMDockWindow(int argc, char **argv)
{
char *displayName = NULL;
// Open display
if ((wDisplay = XOpenDisplay(displayName)) == NULL)
{
std::cerr << APPNAME << ": could not open display " << displayName << std::endl;
exit(0);
}
// Get root window
Root = RootWindow(wDisplay, DefaultScreen(wDisplay));
// Create windows
wAppwin = XCreateSimpleWindow(wDisplay, Root, 0, 0, 64, 64, 5, 5, 0);
WiconWin = XCreateSimpleWindow(wDisplay, wAppwin, 1, 1, 56, 56, 0, 0, 0);
// Set classhint
// to conform to the C char* agasint
// c++ requiring a const char*
classHint.res_name = const_cast<char*>(wInstanceName);
classHint.res_class = const_cast<char*>(wClassName);
XSetClassHint(wDisplay, wAppwin, &classHint);
// Create delete atom
deleteWindow = XInternAtom(wDisplay, "WM_DELETE_WINDOW", False);
XSetWMProtocols(wDisplay, wAppwin, &deleteWindow, 1);
XSetWMProtocols(wDisplay, WiconWin, &deleteWindow, 1);
// Set windowname
XStoreName(wDisplay, wAppwin, APPNAME);
XSetIconName(wDisplay, wAppwin, APPNAME);
// Set sizehints
sizeHints.flags= USPosition;
sizeHints.x = 0;
sizeHints.y = 0;
XSetWMNormalHints(wDisplay, wAppwin, &sizeHints);
// Set wmhints
wmHints.initial_state = WithdrawnState;
wmHints.icon_window = WiconWin;
wmHints.icon_x = 0;
wmHints.icon_y = 0;
wmHints.window_group = wAppwin;
wmHints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
XSetWMHints(wDisplay, wAppwin, &wmHints);
// Set command
XSetCommand(wDisplay, wAppwin, argv, argc);
XMapWindow(wDisplay, wAppwin);
XMapWindow(wDisplay, WiconWin);
XClearWindow (wDisplay,WiconWin);
XFlush (wDisplay);
XSync(wDisplay, False);
}
void WMDockWindow::usage(char **argv)
{
std::cout<<std::endl<<APPNAME<<" "<<AUTHOR<<" "<<VERSION<<" "<<COPYRIGHT<<std::endl<<std::endl
<<argv[0]<<" -p : path to directory of images."<<std::endl
<<argv[0]<<" -f : file containing absoloute path to images."<<std::endl
<<argv[0]<<" -t : delay time in seconds."<<std::endl
<<argv[0]<<" -r : display images in random order."<<std::endl
<<argv[0]<<" -o : displa images in ordered list."<<std::endl<<std::endl
<<APPNAME<<" -t 30 -r -p /path/to/image directory"<<std::endl;
}
you still did not learn. Posted just parts of your files, without names so we need to guess what the heck happening at all. There is no easy way to identiy cpimage.cpp line 37 or others. There no way to know what was cut and why (and was that important or not).
So I can only guess:
WMDockWindow->getDisplay()
and
WMDockWindow.getDisplay()
will only work if getDisplay is a static method of class WMDockWindow - or the class was instantiated, like:
Code:
WMDockWindow *w = new WMDockWindow();
w->getDisplay()
Or, as you instantiated it in main, you need to store it in a (global) variable or....
you still did not learn. Posted just parts of your files, without names so we need to guess what the heck happening at all. There is no easy way to identiy cpimage.cpp line 37 or others. There no way to know what was cut and why (and was that important or not).
So I can only guess:
WMDockWindow->getDisplay()
and
WMDockWindow.getDisplay()
will only work if getDisplay is a static method of class WMDockWindow - or the class was instantiated, like:
Code:
WMDockWindow *w = new WMDockWindow();
w->getDisplay()
Or, as you instantiated it in main, you need to store it in a (global) variable or....
but it was in the back of my mind, how much to post without giving too much. so let me appease you. post #1 updated.
thanks by the way. now I'm going to wait.. because
Code:
||=== Build: Debug in wmslideshow+ (compiler: GNU GCC Compiler) ===|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp||In member function 'void cimage::setImageToDockapp()':|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|37|error: invalid use of incomplete type 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.hpp|6|note: forward declaration of 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|39|error: invalid use of incomplete type 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.hpp|6|note: forward declaration of 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|39|error: invalid use of incomplete type 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.hpp|6|note: forward declaration of 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|42|error: invalid use of incomplete type 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.hpp|6|note: forward declaration of 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|49|error: invalid use of incomplete type 'class WMDockWindow'|
/home/userx/C++Projects/wmslideshow+/cpimage.hpp|6|note: forward declaration of 'class WMDockWindow'|
||=== Build finished: 5 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
but it was in the back of my mind, how much to post without giving too much.
thanks by the way.
For architecture questions like this, you can leave out the function bodies. The class and function definitions (their arguments and return types) are what's important.
For architecture questions like this, you can leave out the function bodies. The class and function definitions (their arguments and return types) are what's important.
that's basically what I thought I did, I gave both classes and only posted the function screwing up.
||=== Build: Debug in wmslideshow+ (compiler: GNU GCC Compiler) ===|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp||In member function 'void cimage::setImageToDockapp()':|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|38|error: incomplete type 'WMDockWindow' used in nested name specifier|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|38|error: incomplete type 'WMDockWindow' used in nested name specifier|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|41|error: incomplete type 'WMDockWindow' used in nested name specifier|
/home/userx/C++Projects/wmslideshow+/cpimage.cpp|48|error: incomplete type 'WMDockWindow' used in nested name specifier|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
(no, it is not solved) you still don't understand, you need static member function, or you need to know the instance (keep it in a variable).
WMDockWindow is not a variable, but a type (a class). You are not allowed to invoke a non-static function of a type - without instance.
(no, it is not solved) you still don't understand, you need static member function, or you need to know the instance (keep it in a variable).
WMDockWindow is not a variable, but a type (a class). You are not allowed to invoke a non-static function of a type - without instance.
O' Tay, I took some steps back and rewrote it without using a class or classes, just straight C++, got all of the kinks worked out of it, and its working without errors. I just turned it into a class and fix my issue with how to get the object into somewhere else. now its loading some other dockapps icon and using that to display instead of the loaded images its getting.
I passed the object into the prams. and I figured out the new issue .. need to fix a means to get the proper data to the image to load it properly.
Yep! I agree. When the need dictates it then I'll be doing that. I just rethought my plan of attack on how should I do this line of thought. As I stated two classes was over kill.
I just did this with my one class that I took it down too,
then used that to pass its members into the functions I needed to access. It compiles with no errors and no more warnings, and does what I want it to do. That being the "main" concern for a program.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.