| deadpickle (1) | |||||||||||
I am trying to use a vector of shared_ptr (boost lib) that points to a class with a nested class (hope I got all that right). So far I have:
and when I go to initialize the class I have:
and just for more info, my header is:
The last two lines are what my question is about. I want to set sites->coord.x but have no clue how to do this. I get that siteptr site_ptr( new Site); is creating a shared pointer that points to the class Site but within new Site do i need to set the value of sites->coord.x = subx like this:
or maybe:
As you can probably tell I'm really not sure. Or can I initialize the class and set the value later? FYI, I'm new to c++ so be gentle. | |||||||||||
|
|
|||||||||||
| ne555 (4035) | |||||
¿Do you know another language? You are confusing classes with objects.
Also
| |||||
|
|
|||||
| mik2718 (295) | |||||||
You need to write constructors for your classes. e.g.
I have put you variables in a private section since this is the normal thing to do (but not a requirement) The constructor I have written uses an initialisation list (and has an empty body) With this constructor you can now create a point like this
or to use a shared_ptr you can use it like this
| |||||||
|
|
|||||||
| andywestken (1950) | |||
|
@deadpickle (aside) if you're doing the allocation and copy just to you can use atof, you're doing too much work. Instead of
just use latlonvar[1] = atof(str.c_str());Also note that you're leaking memory as you don't delete [] cstr; after you've finished using the previous string.Andy | |||
|
Last edited on
|
|||