Implementation problem

K

Kevin Grigorenko

Basically, I have two classes declared in a header file:

class Version
{
...
};

class BasicRegex
{
...
std::vector<std::string> split(std::string parseString);
...
};

Then, in the implementation file, I want to use an instance of the
BasicRegex class in the implementation of a member function of Version. It
seems to compile fine when I declare a local object of type BasicRegex in
the Version member function, but then when I try to call the member function
split(), VS.NET compiler gives the following error:

error C2228: left of '.split' must have class/struct/union type

void Version::setVersion(std::string parseString)
{
if(parseString == "") return;
BasicRegex regex(std::string(separator_)); // separator_ is private
member data in Version, just a char
std::vector<std::string> nums;
nums = regex.split(parseString); // here's the problematic line
nums_.resize(nums.size()); // nums_ is also local data for
Version
for(int i = 0; i < nums.size(); i++)
{
nums_ = std::atoi(nums.c_str());
}
}

I can use the BasicRegex object outside of the implementation file (and the
split member function works fine, so it has something to do with scope here
I think).

What can I do to fix this?

Thank you,
Kevin Grigorenko
 
R

Rob Williscroft

Kevin Grigorenko wrote in
BasicRegex regex(std::string(separator_)); // separator_ is
private

The above declares a function:

BasicRegex regex( std::string seperator );

Parenthesis are allowed to surround the identifier part of a declaration
to allow stuff like:

int (*pointer_to_array)[3];

Solution 1:

BasicRegex regex( (std::string( seperator ) ) );

Solution 2 (needs an accesable copy-ctor, but shouldn't call it):

BasicRegex regex = BasicRegex( std::string( seperator ) );

HTH.

Rob.
 
K

Kevin Grigorenko

Rob Williscroft said:
Kevin Grigorenko wrote in
BasicRegex regex(std::string(separator_)); // separator_ is
private

The above declares a function:

BasicRegex regex( std::string seperator );

Parenthesis are allowed to surround the identifier part of a declaration
to allow stuff like:

int (*pointer_to_array)[3];

Solution 1:

BasicRegex regex( (std::string( seperator ) ) );

Wow, that was simple, Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top