|
"hi i need this program immediately in c++"
Sure. My usual fee for doing someone else's homework for them is $500 US per hour with a 4 hour minimum.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
sonuchill wrote: Write a class...
I'm pretty sure that means you, not us.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
But your teacher didnt say anything to us for write this program?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Maybe he did - maybe progressive colleges are now teaching "How to get answers from CodeProject"...the OP's failed that course as well
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
sonuchill wrote: hi i need this program immediately in c++
Sorry, time is up.
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]
|
|
|
|
|
No man. *New* is always *New* as long as it is tagged.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
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 meant immediately is always immediately no matter when you read it.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Use of Add time.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
sonuchill, this is your professor writing.
See me before the start of the next class.
|
|
|
|
|
Pressure sometimes really helps!!!
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
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?
|
|
|
|
|