|
Hi everyone. I have a rather simple(or so i thought) problem. I cant seem to pass, and recieve a pointer to a list.I need access to this list so i can add a newly created object(of the class sphere) into it!
I am calling a method of a class Sphere like this:
class sphere{
int id, promjer, x, y;
sphere(int idd, int ppromj, int xx, int yy, std::list<sphere> *llist_of_classes)
: id(idd), promjer(ppromj), x(xx), y(yy){
llist_of_classes.push_back(this);
}
std::list<sphere> list_of_classes;
void main(){
...
sphere Ball(1,2,3, &list_of_classes);
}
I get the 'cannot convert paramater 5 from..to..' error msg. Does anyone have any idea how to solve this problem?
Or more generally, how do i pass and recieve pointers to std::list?!
thx!
|
|
|
|
|
Isn't std::list a template, doesn't it need template arguments (type of list elements and such)? What is the exact error message you get?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Yes it does, the code i supplied was not actual! for which i am sorry. Check out the code in an answer to a poster below!
thx!
|
|
|
|
|
Ok, sorry for the nitpicking. I believe your problem is that you should use llist_of_classes->push_back(this); instead of llist_of_classes.push_back(this); in the constructor of your sphere since it is a pointer not the object (or a reference to the object) itself.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
i've tried before, and this is what i've got:
error C2664: 'std::list<_Ty>::push_back' : cannot convert parameter 1 from 'sphere *const ' to 'const sphere &'
but it does make sense what you are saying, the solution will probably have the '->'
thanks!
|
|
|
|
|
Do you want to put pointers in that list? If your answer is yes then you probably need to change the template parameter for the std::list (something like std::list<my_class*> instead of std::list<my_class> i guess), if no, then you probably need to use ...pushback(*this); instead of pushback(this).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
You are right! i finally got it to work
the solution:
llist_of_classes->push_back(*this);
Thank you!
|
|
|
|
|
No probs, glad i could help.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Firstly revise your post: you can't see any of the < or > characters or what's between them. Now to your problem, the constructor to your class looks like this:
sphere(int idd, int ppromj, int xx, int yy, std::list<sphere> *llist_of_classes)
That's four int s and a pointer to a std::list .
The code your having problems with looks like this:
Member 3885283 wrote: sphere Ball(1,2,3, &list_of_classes);
Here you're passing three int s and a pointer to a std::list .
Steve
|
|
|
|
|
First off, thanks for the reply. Now to the code. This is the actual code i should have posted earlier, this is the actual full code:
I am not sure what you mean by not being able to see whats between the <> and the brackets themselves? what am i doing wring?
#include "stdlib.h"
#include "stdio.h"
#include "Sphere.h"
#include <list>
extern std::list<sphere>list_of_classes;
extern std::list<sphere>::const_iterator iterator;
#include <list>
class sphere{
public:
int id;
int promjer;
int x;
int y;
sphere(int idd, int ppromj, int xx, int yy, std::list<sphere> *llist_of_classes) : id(idd), promjer(ppromj), x(xx), y(yy){
llist_of_classes.push_back(this);
};
};
#include "sphere.h"
#include "util.h"
std::list<sphere>list_of_classes;
std::list<sphere>::const_iterator iterator;
void main(){
sphere objekt(1,2,3,4,&list_of_classes);
for(iterator=list_of_classes.begin(); iterator!=list_of_classes.end(); ++iterator)
{
printf("kugla:%d, promjer: %d, x: %d, y: %d\n",iterator->id, iterator->promjer, iterator->x, iterator->y);
}
getchar();
}
this code generates C2228:left of '.push_back' must have class/struct/union <-3times
This is the entire literal code.
All i need is a way to correctly pass a pointer to the list, add the newly created sphere object in its constructor into the list, and thats it!
Anyone spot the problem?
thank you!
|
|
|
|
|
Avion85 wrote: I am not sure what you mean by not being able to see whats between the <> and the brackets themselves? what am i doing wring?
You need to escape the < by replacing it with < - easiest way is to tick the 'Encode HTML tags when pasting' checkbox below the Text: field when pasting code into a message.
As to your problem...
llist_of_classes.push_back(this);
llist_of_classes is a pointer, not a reference or a value. So, the dot operator won't work with it - use the -> operator!
llist_of_classes->push_back(this);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you all for the solution! it finally works, and this is it:
sphere(int idd, int ppromj, int xx, int yy, std::list<sphere> *llist_of_classes) : id(idd), promjer(ppromj), x(xx), y(yy){
llist_of_classes->push_back(*this);
}
sphere objekt(1,2,3,4,&list_of_classes);
This forum is awesome.A fact.
|
|
|
|
|
Hi,
How to register a window of Dialog Based Application?
|
|
|
|
|
|
U can do the registration in 'InitInstance' method of Application derived class(before 'DoModal' of the main dialog)
WNDCLASS wc = {0};
wc.style = CS_BYTEALIGNWINDOW|CS_SAVEBITS|CS_DBLCLKS;
wc.lpfnWndProc = DefDlgProc;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = m_hInstance;
wc.hIcon = LoadIcon(IDR_MAINFRAME);
wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
wc.lpszClassName = <Specify the class name here as well as in .rc>
ATOM cls = RegisterClass(&wc);
|
|
|
|
|
i need help for code for fast algorithm to compute Walsh Hadamard coefficient
|
|
|
|
|
What is your trouble with?
What have you done, so far?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i have problem in calculation of value
w(k+1,b)=(w(k,b)+w(k+1,2b),w(k,b),w(k+1,2b))
how i write this in C
|
|
|
|
|
ahmedbhatti wrote: w(k+1,b)=(w(k,b)+w(k+1,2b),w(k,b),w(k+1,2b))
It strongly depends on the meaning of such expression, I suppose...
I.e. what is w(k,b) ? What is (w(..),w(..),w(..)) ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Assalamo 3aliko
I need c++ program for OFDM techniques in WIMAX system
pleas if any one have it send it for me
thanks a lot
|
|
|
|
|
rent-a-coder looks like a viable solution.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How to execute inf files from C++ code. My Device Driver are having .inf file with some other file. I want to execute inf file for installing Device Driver.
|
|
|
|
|
See ShellExecute[^] with 'verb' set to 'open'
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You can execute a particular section in an INF file using the InstallHinfSection function.
See the documentation of InstallHinfSection[^] for more information.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hello to all,
In my project I am uploading some data on to the internet.After data uploading gets completed without any problem then one modal dialog box appears showing the text "Uploaded Successfully" (I am invoking that dialog box through "AfxMessageBox"). Now I want to play one "avi" file on to that dialog box or I want to show some moving image on to that dialog box. So anyone knows how to do it? anyone knows how to play "avi" file on modal dialog box? its really urgent so plz help me out.
Thanks and Regards,
Anay
|
|
|
|
|