473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing pointer as parmaneter

I have to pass a pointer as a parameter, but I can't quite get the syntax down.

I have this variable:
std::vector<Foo> fooVector;

And this function of another class, Foo
void Add (Foo * N)

So I need to pass fooVector_[size_t] to the Add function.

I have tried this:
Foo foo;
foo.Add(foo.fooVector_[size_t]) but get the error (shortened) Needs class::Foo* not class::Foo&

Could you please point* me in the right direction.
Mar 25 '10 #1
6 1253
weaknessforcats
9,208 Expert Mod 8TB
fooVector is implemented as an array of foo. Therefore, fooVector[size_t] is a foo. Therefore, &fooVector[size_t] is a foo*.
Mar 25 '10 #2
Thanks so much, weaknessforcats!
Mar 25 '10 #3
So, say that the void Add(Foo * N) function has access to a private variable that is a list and I want to add more than one item at any given item in the list. For instance, I want to add a North, and South to item 0 in the list, how can I do this?
Mar 27 '10 #4
Banfa
9,065 Expert Mod 8TB
Call the function twice, unless you are able to write a function with more semantic meaning such as

Expand|Select|Wrap|Line Numbers
  1. void Foo::AddExits(Foo* northExit, Foo* southExit, Foo* eastExit, Foo* WestExit);
Mar 27 '10 #5
Banfa, thanks, but I was going in the wrong direction with that.
However, say I have
Expand|Select|Wrap|Line Numbers
  1. class Foo
  2. {
  3.   Bar * start;
  4.   start = &fooVector[size_t]
  5. ...
  6. }
  7. class Bar
  8. {
  9. ...
  10. }
How can I output the value of start? I did not overload the operator << so I cannot cout << *start
Mar 28 '10 #6
weaknessforcats
9,208 Expert Mod 8TB
You would need to call methods on class Bar that return the values you are interested in.
Mar 28 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
1
by: george doubleu | last post by:
hi, i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below. I get the two warnings you can see in the remarks. The second warning is perfectly OK for me, but the first one I...
17
by: LP | last post by:
Hello, Here's the scenario: Object A opens a Sql Db connection to execute number of SqlCommands. Then it needs to pass this connection to a constructor of object B which in turn executes more...
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
6
by: Roman Mashak | last post by:
Hello, I belive the reason of problem is simple, but can't figure out. This is piece of code: struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ };
8
by: Ivan Liu | last post by:
Hi, I'd like to ask if passing an object as an pointer into a function evokes the copy constructor. Ivan
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
7
by: pereges | last post by:
which one do you think is better ? I need to make my program efficient and in some places I have passed the copy of a variable which makes life some what easy while writing huge expressions but...
5
by: CapCity | last post by:
I'm sure I'm missing something simple - I do not code in C regularly, and the breaks are long enough for me to forget. The situation I have is I need to create an array but I do not know the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.