?
Solved

Sntax Error

Posted on 2011-04-28
16
Medium Priority
?
402 Views
Last Modified: 2013-12-16
Hi guys: Can any one please help me in that error. Thanks.

class Employee
{
      public:
             string name;
             double salary;
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}


Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:5: error: `string' does not name a type

C:\Documents and Settings\Kathy\My Documents\test.cpp:11: error: definition of implicitly-declared `Employee::Employee()'
C:\Documents and Settings\Kathy\My Documents\test.cpp:11: error: declaration of `Employee::Employee()' throws different exceptions
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: than previous declaration `Employee::Employee() throw ()'
C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before "n"

Execution terminated
0
Comment
Question by:mustish1
  • 8
  • 8
16 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488913
is this c++ or c#?

I think it should be: (sorry if not 100% correct)
c#
class Employee
{
      public:
             string name;
             double salary;

      Employee()
      {
          name = "";
          salary = 0.0;
      }

      Employee(string n, double s)
      {
        name = n;
        salary = s;
      }
}

Open in new window


c++
class Employee
{
      public string name;
      public double salary;

      public Employee();
      public Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
 

Author Comment

by:mustish1
ID: 35488934
Thanks. Its a C++

class Employee
{
      public string name;
      public double salary;

      public Employee();
      public Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}



Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: expected `:' before "string"
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: `string' does not name a type
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: expected `:' before "double"
C:\Documents and Settings\Kathy\My Documents\test.cpp:6: error: expected `:' before "Employee"

C:\Documents and Settings\Kathy\My Documents\test.cpp:7: error: expected `:' before "Employee"

C:\Documents and Settings\Kathy\My Documents\test.cpp:7: error: expected `)' before "n"

C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before "n"

Execution terminated
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488950
sorry i did the class declaration
 
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488952
i think i have gotten a little bit confused.

are you including a header for the type "string"?
0
 

Author Comment

by:mustish1
ID: 35488956
Thanks. It still give error on that line
string name;

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:17: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:17: error: expected `,' or `;' before "n"

Execution terminated


class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488966
is that the whole cpp file?
0
 

Author Comment

by:mustish1
ID: 35488968
#include<iostream>
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
0
 

Author Comment

by:mustish1
ID: 35488975
Yes.
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488978
#include<iostream>

class Employee
{
      public:
            std::string name;
            double salary;

            Employee();
            Employee(std::string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(std::string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
 

Author Comment

by:mustish1
ID: 35488982
im sorry. I think main is missing in that. I am just trying to play with the object oriented programming.
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35488988
yer you need a main

also you need to add
std:: before and string declarations
eg:
std::string name;
0
 

Author Comment

by:mustish1
ID: 35489000
Can you please tell me the changes in the code



class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

int main()
#include<iostream>
{
      system("pause");
      return 0;
}
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35489003
from you original?

#include<iostream> should be at the top of the file
0
 

Author Comment

by:mustish1
ID: 35489008
Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:5: error: `string' does not name a type

C:\Documents and Settings\Kathy\My Documents\test.cpp:9: error: expected `)' before "n"

C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:18: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:18: error: expected `,' or `;' before "n"

Execution terminated



#include<iostream>
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

int main()
{
      system("pause");
      return 0;
}
0
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 2000 total points
ID: 35489014
replace every
 "string"
with
"std::string"
0
 

Author Closing Comment

by:mustish1
ID: 35489025
Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question