6 Replies - 4649 Views - Last Post: 22 April 2009 - 10:55 PM Rate Topic: -----

#1 Shardok   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-April 09

Yeah, Expected primary-expression before...

Post icon  Posted 22 April 2009 - 06:11 PM

error: expected primary-expression before 'char'

		
		 cout << "What do you wish to append?"
		 << endl;
		 cin  >> line;
		 list::append(char line[]);
	}



class list

{

	public:

		  list();

		  ~list();

		  int append(char line[]);

		  int remove(char line[]);

 


Now, the problem that it is referring to is the 4th line in the first set of code. I can't seem to find any idea why it keeps giving me that error or what to do to fix it, obviously. The second part of code is the declaration of the function I'm trying to call.

Is This A Good Question/Topic? 0
  • +

Replies To: Yeah, Expected primary-expression before...

#2 ccubed   User is offline

  • It's That Guy
  • member icon

Reputation: 164
  • View blog
  • Posts: 1,416
  • Joined: 13-June 08

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 06:14 PM

Just checking the basics, did you include your .h file in the .cpp file? Other then that, I can't see any reason why. Unless you have the class declaration in your CPP file and it's after the first call to list::append. BTW, Append is a C++ function already so you might try changing the name.

This post has been edited by ccubed: 22 April 2009 - 06:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 mikeblas   User is offline

  • D.I.C Regular
  • member icon

Reputation: 44
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 06:19 PM

View PostShardok, on 22 Apr, 2009 - 05:11 PM, said:

Now, the problem that it is referring to is the 4th line in the first set of code. I can't seem to find any idea why it keeps giving me that error or what to do to fix it, obviously. The second part of code is the declaration of the function I'm trying to call.
You're trying to call the function, so you don't need to specify the "char" data type there. In C++, you specify data types on parameters in function declarations and definitions, but not at call sites.
Was This Post Helpful? 0
  • +
  • -

#4 Shardok   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-April 09

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 08:22 PM

Yes, the .h file is included. And the class is declared in the .h file, but the function later defined in the .cpp file. Oh, and just to check, when it's defined, I do define it like this, right?
int list::append(char line[])
{
what it does
}
 


I get this error when I remove the char from the call of the function.

main1.cpp:31: error: expected primary-expression before ']' token

This post has been edited by Shardok: 22 April 2009 - 08:23 PM

Was This Post Helpful? 0
  • +
  • -

#5 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 611
  • Joined: 24-July 08

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 09:15 PM

View PostShardok, on 22 Apr, 2009 - 05:11 PM, said:

	
		char * line;  //define the char* line
		list List //get a pointer to your class

		 cout << "What do you wish to append?"<< endl; //easier to read if you keep it on the same line
		 cin  >> line;
		 list::append(char line[]); //Why would you do this??  This is like declaring the function, not calling it.
				 // Should be like this
		List.append(line);
				 
	}



class list

{

	public:

		  list();

		  ~list();

		  int append(char line[]);

		  int remove(char line[]);
};  //You forgot this.....

 


Check the modifications/notes made

This post has been edited by UG Cyber: 22 April 2009 - 09:24 PM

Was This Post Helpful? 0
  • +
  • -

#6 Shardok   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-April 09

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 10:39 PM

All right, yeah, I know I forgot the }; at the end of the class, that's because the class didn't actually end there, that was the only part of it I felt necessary to post to get the point across. And after having changing the thing you mentioned it has fixed it. Thanks to all of you. I guess I forgot a bit of stuff since I took my previous C++ class.

Thanks again, oh look, it actually compiled.
Was This Post Helpful? 0
  • +
  • -

#7 Shardok   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-April 09

Re: Yeah, Expected primary-expression before...

Posted 22 April 2009 - 10:55 PM

Whoops

This post has been edited by Shardok: 23 April 2009 - 06:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1