473,321 Members | 1,622 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,321 software developers and data experts.

Access members of a typedef vector

2
Hi every one. I which you all a prosperous 2007.

I would appreciate it if someone can point me in the right direction.

I have a two classes Class1 and Class2.

In Class2 I have a

typedef std::vector<Class1*> FluidCell;
FluidCell fc;

I access the member of "fc" with a for loop and an iterator.
typedef FluidCell::iterator Iter ;

for((Iter k = fc.begin(); k != fc.end(); k++){

//I try to access the public functions in Class1 like this

k->Class1Func();
}

and get a compile error

/home/chr/cc/convert/src/class2.cpp:293: error: request for member `Class1Func' in `k->', which is of non-class type `Class1*'
Jan 11 '07 #1
2 2112
arne
315 Expert 100+
Hi every one. I which you all a prosperous 2007.

I would appreciate it if someone can point me in the right direction.

I have a two classes Class1 and Class2.

In Class2 I have a

typedef std::vector<Class1*> FluidCell;
FluidCell fc;

I access the member of "fc" with a for loop and an iterator.
typedef FluidCell::iterator Iter ;

for((Iter k = fc.begin(); k != fc.end(); k++){

//I try to access the public functions in Class1 like this

k->Class1Func();
}

and get a compile error

/home/chr/cc/convert/src/class2.cpp:293: error: request for member `Class1Func' in `k->', which is of non-class type `Class1*'

You may try
Expand|Select|Wrap|Line Numbers
  1. (*k)->Class1Func();
  2.  
k is no pointer to a Class1 class.
Jan 11 '07 #2
Ganon11
3,652 Expert 2GB
Since k is an iterator, it is a pointer to the data inside the vector. The data is of type *Class1. So k is effectively of type **Class1. The -> resolves one of these pointers, but you are still trying to access the function *Class1::Class1Func(), which doesn't exist. You can either use (*k)->Class1Func() (which would resolve both pointers), or you can declare your FluidCell typedef to be a vector of type Class1 instead of type *Class1.
Jan 11 '07 #3

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

Similar topics

12
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of...
2
by: gvdeynde | last post by:
Hi, What's the "best" way to have an object ObjA of class A have read-access (but not write-access) to a data member of object ObjB of class B. Class B has a std::vector<T> as a datamember. ObjA...
5
by: Russell Shaw | last post by:
Hi, In setjmp.h on a linux system, there is: typedef struct __jmp_buf_tag { ... } jmp_buf; I could understand typedef struct { } jmp_buf, but how do i interpret typedef struct { } jmp_buf ?
8
by: Allerdyce.John | last post by:
Is it a good practice in C++ to: 1. create a typedef for my STL container of my class? like this: typedef vector<A> AList; and I create my vector of A using this: AList* aList = new...
23
by: sidney | last post by:
Hi all, I am trying to make a vector containing objects the have a reference member. However, as soon as I try to push_back an element into this vector, g++ balks at the fact that it needs to...
5
by: andrewmorrey | last post by:
Hello, I've got a VC++ project containing multiple classes and a main function. In one of the class functions, it reads from a text file and places the data into a vector; //...
2
by: DhaneshNair | last post by:
I have created a COM server in which a collection of vectors need to be exposed to C# sharp client . Each vector contains a array of structures and this vector need to be embedded inside a...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are...
85
by: pereges | last post by:
#include <stdio.h> typedef struct { double x, y, z; }vector; int main(void) { int i;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.