473,605 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about static vector (of pointers) member function


Hello, is someone so kind to tell me why I am getting the following
errors ?
vector_static_f unction.c:20: error: expected constructor, destructor,
or type conversion before '.' token
vector_static_f unction.c:21: error: expected constructor, destructor,
or type conversion before '.' token
when compiling this:
// about static vector (of pointers) member function

#include <iostream>
#include <vector>
using namespace std;

class G4PreCompoundMo del
{
public:
static vector<int** GetCreatorModel s()
{ return &G4PreCompoundM odel::theCreato rModels; }

// private:

static vector<int*theC reatorModels;

};

int uno=1, dos=2;
G4PreCompoundMo del::theCreator Models.push_bac k(&uno);
G4PreCompoundMo del::theCreator Models.push_bac k(&dos);

int main ()
{
G4PreCompoundMo del::GetCreator Models();
return 0;
}

Thanks in advance amd best regards

Jose Manuel

May 19 '07 #1
4 3499
Josefo wrote:
Hello, is someone so kind to tell me why I am getting the following
errors ?
vector_static_f unction.c:20: error: expected constructor, destructor,
or type conversion before '.' token
vector_static_f unction.c:21: error: expected constructor, destructor,
or type conversion before '.' token
when compiling this:
// about static vector (of pointers) member function

#include <iostream>
#include <vector>
using namespace std;

class G4PreCompoundMo del
{
public:
static vector<int** GetCreatorModel s()
{ return &G4PreCompoundM odel::theCreato rModels; }

// private:

static vector<int*theC reatorModels;

};

int uno=1, dos=2;
G4PreCompoundMo del::theCreator Models.push_bac k(&uno);
^^^^^^^ what is this supposed to be ? A statement is not allowed here,
it must be in a function block.

Look up your C++ book on how to define static data members and how to
initialize them.
G4PreCompoundMo del::theCreator Models.push_bac k(&dos);

int main ()
{
G4PreCompoundMo del::GetCreator Models();
return 0;
}

Thanks in advance amd best regards

Jose Manuel
May 19 '07 #2
On May 19, 1:46 pm, Josefo <josemanue...@g mail.comwrote:
Hello, is someone so kind to tell me why I am getting the following
errors ?

vector_static_f unction.c:20: error: expected constructor, destructor,
or type conversion before '.' token
vector_static_f unction.c:21: error: expected constructor, destructor,
or type conversion before '.' token

when compiling this:

// about static vector (of pointers) member function

#include <iostream>
#include <vector>
using namespace std;

class G4PreCompoundMo del
{
public:
static vector<int** GetCreatorModel s()
{ return &G4PreCompoundM odel::theCreato rModels; }

// private:

static vector<int*theC reatorModels;
Where is the definition for this static member?
>
};

int uno=1, dos=2;
G4PreCompoundMo del::theCreator Models.push_bac k(&uno);
G4PreCompoundMo del::theCreator Models.push_bac k(&dos);
These push_back() calls are not allowed outside main() or another
function. You can't code anything else but a declaration or a
definition in a namespace (in this case: the global namespace).
>
int main ()
{
G4PreCompoundMo del::GetCreator Models();
return 0;

}

Thanks in advance amd best regards

Jose Manuel

May 19 '07 #3
Josefo wrote:
Hello, is someone so kind to tell me why I am getting the following
errors ?
vector_static_f unction.c:20: error: expected constructor, destructor,
or type conversion before '.' token
vector_static_f unction.c:21: error: expected constructor, destructor,
or type conversion before '.' token
when compiling this:
// about static vector (of pointers) member function

#include <iostream>
#include <vector>
using namespace std;

class G4PreCompoundMo del
{
public:
static vector<int** GetCreatorModel s()
{ return &G4PreCompoundM odel::theCreato rModels; }

// private:

static vector<int*theC reatorModels;

};

int uno=1, dos=2;
G4PreCompoundMo del::theCreator Models.push_bac k(&uno);
G4PreCompoundMo del::theCreator Models.push_bac k(&dos);

int main ()
{
G4PreCompoundMo del::GetCreator Models();
return 0;
}

Thanks in advance amd best regards

Jose Manuel
Here's how to write your code so that it works, (basically your design
has static in the wrong place)

class G4PreCompoundMo del
{
public:
static G4PreCompoundMo del& GetCreatorModel s()
{
static G4PreCompoundMo del theModel;
return theModel;
}

private:
G4PreCompoundMo del()
{
uno = 1;
dos = 2;
theCreatorModel s.push_back(&un o);
theCreatorModel s.push_back(&do s);
}

int uno;
int dos;
vector<int*theC reatorModels;

};

Now all you have to do is add whatever methods you require to
G4PreCompoundMo del.

john
May 20 '07 #4
On May 20, 8:45 am, John Harrison <john_androni.. .@hotmail.comwr ote:
Josefo wrote:
Hello, is someone so kind to tell me why I am getting the following
errors ?
vector_static_f unction.c:20: error: expected constructor, destructor,
or type conversion before '.' token
vector_static_f unction.c:21: error: expected constructor, destructor,
or type conversion before '.' token
when compiling this:
// about static vector (of pointers) member function
#include <iostream>
#include <vector>
using namespace std;
class G4PreCompoundMo del
{
public:
static vector<int** GetCreatorModel s()
{ return &G4PreCompoundM odel::theCreato rModels; }
// private:
static vector<int*theC reatorModels;
};
int uno=1, dos=2;
G4PreCompoundMo del::theCreator Models.push_bac k(&uno);
G4PreCompoundMo del::theCreator Models.push_bac k(&dos);
int main ()
{
G4PreCompoundMo del::GetCreator Models();
return 0;
}
Thanks in advance amd best regards
Jose Manuel

Here's how to write your code so that it works, (basically your design
has static in the wrong place)

class G4PreCompoundMo del
{
public:
static G4PreCompoundMo del& GetCreatorModel s()
{
static G4PreCompoundMo del theModel;
return theModel;
}

private:
G4PreCompoundMo del()
{
uno = 1;
dos = 2;
theCreatorModel s.push_back(&un o);
theCreatorModel s.push_back(&do s);
}

int uno;
int dos;
vector<int*theC reatorModels;

};

Now all you have to do is add whatever methods you require to
G4PreCompoundMo del.

john
Thanks, John for your assistance. A sent a reply yesterday, but it
does not appear published. Therefore, I write it again (sorry in
advance if it shows up duplicated).Wel l, when I received your
suggestion I had already more or less "elegantly" (or efficiently)
solved the problem. Here you have the code:
///begin of the code
// about static vector (of pointers) member function
//19/05/07...my solution

#include <iostream>
#include <vector>
using namespace std;

class G4PreCompoundMo del
{
public:
static int uno, dos;

static vector<int** GetCreatorModel s()
{ return &
G4PreCompoundMo del::theCreator Models; }

// private:

static vector<int*theC reatorModels;

private:
static bool __init;
static bool init() {
theCreatorModel s.push_back(&un o);
theCreatorModel s.push_back(&do s);
return true;
}
};
int G4PreCompoundMo del::uno=1;
int G4PreCompoundMo del::dos=2;
vector<int*G4Pr eCompoundModel: :theCreatorMode ls;
bool G4PreCompoundMo del::__init = G4PreCompoundMo del::init();

int main ()
{
int uno=1,dos=2;
vector<int** p=G4PreCompound Model::GetCreat orModels();
cout<<"The returned pointer 'p' (to vector of pointers to integers)=
"<<p<<endl;

int ** p1;
int ** p2;
p1=&((*p).at(0) )+1;
p2=&((*p).at(1) );

if(uno==*((*p). at(0)) && dos==*((*p).at( 1)))

cout<<"Ok...uno =*((*p).at(0)) = "<<*((*p).at(0) )<<" and dos =
*((*p).at(1)) ="<<*((*p).at(1 ))<<endl;
if (p1==p2)
{cout<<"Right!. .the pointers (to vector member pointers to integers)
are sequential!!"<< endl;
cout<<"&((*p).a t(0))+1="<<&((* p).at(0))+1<<"
&((*p).at(1))=" <<p2<<endl;}
cout<<"The vector member pointers (to integers..) are not sequential
(why shoud they?):"<<endl;
cout<<"(*p).at( 0) = "<<(*p).at(0)<< " (*p).at(1) =
"<<(*p).at(1)<< endl;
return 0;
}

////// end of the code

When implementing your suggestion I had to comment the /private
declaration in G4PreCompoundMo del class in order to have acces to its
constructor and hence to ints vector members. Here you hacve it:
///begin of the code
// about static vector (of pointers) member function
//20/05/07...John Allison's solution

#include <iostream>
#include <vector>
using namespace std;
class G4PreCompoundMo del
{
public:
static G4PreCompoundMo del& GetCreatorModel s()
{
static G4PreCompoundMo del theModel;
return theModel;
}

// private:
G4PreCompoundMo del()
{
uno = 1;
dos = 2;
theCreatorModel s.push_back(&un o);
theCreatorModel s.push_back(&do s);
}

int uno;
int dos;
vector<int*theC reatorModels;

};
int main ()
{
int uno=1,dos=2;
int * puno;
int * pdos;
puno =G4PreCompoundM odel::GetCreato rModels().theCr eatorModels.at( 0);
pdos =G4PreCompoundM odel::GetCreato rModels().theCr eatorModels.at( 1);

if(uno==*puno && dos==*pdos)
cout<<"Ok...uno =*puno = "<<*puno<<" and dos = *pdos
="<<*pdos<<endl ;
if (&puno+1==&pdos ) {
cout<<"The pointers (to vector member pointers to integers) are
sequential:"<<e ndl;
cout<<"&puno+1= "<<&puno+1< <" &pdos="<<&pdos< <endl;
cout<< "why they are not????"<<endl; }
else
{ cout<<" The pointers (to vector member pointers to integers) are
NOT sequential:"<<e ndl;
cout<<"&puno+1= "<<&puno+1< <" &pdos="<<&pdos< <endl;
cout<< "why ????"<<endl;}
cout<<"The vector member pointers (to integers..) are not sequential
(why shoud they?):"<<endl;
cout<<"puno = "<<puno<<" pdos = "<<pdos<<en dl;

return 0;
}

///end of the code

But which puzzles me is the fact that the pointers to the vector
members (also pointers to integers, by he way) are not
sequential...an d they are sequential when constructucted in "my
way" (my code). Can you tell me why?? Cheers and many thanks in
advance

Jose Manuel
Jose Manuel

May 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2244
by: cppaddict | last post by:
Hi, I have the following line inside one of my class member functions: static bool tested = false; if (!tested) { MessageBox(NULL, "Hi", "Testing", MB_OK | MB_ICONEXCLAMATION); tested = true; }
37
4979
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
3
1946
by: xuatla | last post by:
Hi, I have a problem about using a class member function as a parameter in another function. What I tried to implement is something like described below: class A { public:
5
651
by: Tony Johansson | last post by:
Hello experts! Why is not possible to have virtual static members Many thnakn //Tony
7
3016
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class is a helper Singleton class, and is created & deleted as and when required) - Where does the static pointer point to when every single instance of the class is deleted. I presume it'll be dangling pointer- as the code seg to which it's
3
1439
by: PengYu.UT | last post by:
I have the following two program. The first one compiles well, but the second one doesn't. The only difference between them is one more template parameter is added for the second program. Would you please help on how to make the second program work? Thanks, Peng /************first************************/
3
1483
by: Sharpdew | last post by:
class Test { double i; public: void fun(){} void foo(void) { cout << "as"; }
1
1348
by: ndbecker2 | last post by:
In the following: class X { void F() { static int g; } }; In a non-member function, static data is has static lifetime. In a member function, is a single static value shared amongst all intances
4
4393
by: Immortal_Nephi | last post by:
I had a lot of research to see how function pointer works. Sometimes, programmers choose switch keyword and function in each case block can be called. Sometimes, they choose ordinary function pointer array instead of switch. They believe that ordinary function pointer is much faster than switch. Think of one variable called selectFunction. selectFunction variable can be the range of 0 through 1,000 or more. Load selectFunction...
0
8001
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8424
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8415
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1270
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.