non-aggregate error

C

Charles Jamieson

I am getting an inexplicable compile-time error message. Here is the code

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));
char* record = db.readUsingKeyword(argv[2]);
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I have extracted the relevant parts of the code. These are the lines
that produce the error.

Here is the error message from gcc 3.3.3

search_test.cpp:15: error: request for member `readUsingKeyword' in
`db', which
is of non-aggregate type `CBerk ()(std::string*)'

I cannot see any problem with this.

-charles
 
J

Jonathan Turkanis

Charles Jamieson said:
I am getting an inexplicable compile-time error message. Here is the code

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));

^^^^^ This is interpretted as a function declaration. So db is not
of type CBerk.
char* record = db.readUsingKeyword(argv[2]);
}> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Try:

CBerk db((std::string(argv[1])));

(((note extra parentheses)))

Jonathan
 
C

Charles Jamieson

Jonathan said:
I am getting an inexplicable compile-time error message. Here is

the code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));


^^^^^ This is interpretted as a function declaration. So db is not
of type CBerk.

char* record = db.readUsingKeyword(argv[2]);
}>

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Try:

CBerk db((std::string(argv[1])));

(((note extra parentheses)))

Jonathan
Thanks, you are right. But I still don't understand it. If I replace
this line with the following two lines:

std::string name(argv[1]);
CBerk db(name);

It compiles with no error. What is the significant difference between
the two?

-charles
 
V

Victor Bazarov

Charles Jamieson said:
Jonathan said:
I am getting an inexplicable compile-time error message. Here is

the code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));


^^^^^ This is interpretted as a function declaration. So db is not
of type CBerk.

char* record = db.readUsingKeyword(argv[2]);
}>

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Try:

CBerk db((std::string(argv[1])));

(((note extra parentheses)))

Jonathan
Thanks, you are right. But I still don't understand it. If I replace
this line with the following two lines:

std::string name(argv[1]);
CBerk db(name);

It compiles with no error. What is the significant difference between
the two?

std::string(whatever)

is a declaration. The optional parentheses around the parameter name
preceded by a type-id in a function declaration. Same as

void foo(int(a));

Remove the parentheses and you will have

void foo(int a);

(less mystery, ain't it?) So, in your declaration it's the same as

void deebee(int(a[2]));

or

void deebee(int a[2]);

which is the same as

void deebee(int a[]);

or

void deebee(int *a);

Do you recognize it as a function declaration now? Replace 'void'
with 'CBerk', 'deebee' with 'db', 'int' with 'std::string'. Nothing
changes from semantic point of view.

For the definitiveness' sake the preference was given to declarations.
If anything _can_ be interpreted as a declaration, it will.

Victor
 
C

Charles Jamieson

Victor said:
Charles Jamieson said:
Jonathan said:
I am getting an inexplicable compile-time error message. Here is

the code


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));


^^^^^ This is interpretted as a function declaration. So db is not
of type CBerk.



char* record = db.readUsingKeyword(argv[2]);
}>

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Try:

CBerk db((std::string(argv[1])));

(((note extra parentheses)))

Jonathan

Thanks, you are right. But I still don't understand it. If I replace
this line with the following two lines:

std::string name(argv[1]);
CBerk db(name);

It compiles with no error. What is the significant difference between
the two?


std::string(whatever)

is a declaration. The optional parentheses around the parameter name
preceded by a type-id in a function declaration. Same as

void foo(int(a));

Remove the parentheses and you will have

void foo(int a);

(less mystery, ain't it?) So, in your declaration it's the same as

void deebee(int(a[2]));

or

void deebee(int a[2]);

which is the same as

void deebee(int a[]);

or

void deebee(int *a);

Do you recognize it as a function declaration now? Replace 'void'
with 'CBerk', 'deebee' with 'db', 'int' with 'std::string'. Nothing
changes from semantic point of view.

For the definitiveness' sake the preference was given to declarations.
If anything _can_ be interpreted as a declaration, it will.

Victor

Thanks for the explanation. It makes sense now.

-charles
 
A

Anil Mamede

Thanks, you are right. But I still don't understand it. If I replace
this line with the following two lines:

std::string name(argv[1]);
CBerk db(name);

It compiles with no error. What is the significant difference between
the two?

-charles

name is a variable instead of a type.

Anil Mamede
 
O

Old Wolf

Charles Jamieson said:
#include <string>

class CBerk
{
public:
CBerk();
CBerk( std::string ) {}

char *readUsingKeyword( char *keyword ) {}
};

main( int argc, char *argv[] )
{
CBerk db(std::string(argv[1]));
char* record = db.readUsingKeyword(argv[2]);
}

std::string can be constructed from (char *), so you could avoid the
issue with:
CBerk db(argv[1]);
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top