Syntax error message for ctor

This is a discussion on Syntax error message for ctor within the C++ Programming forums, part of the General Programming Boards category; Hi I'm having some trouble trying to figure out my syntax error on my code. I have inspected it many ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    53

    Syntax error message for ctor

    Hi

    I'm having some trouble trying to figure out my syntax error on my code. I have inspected it many times, but I can't seem to find my error. The compiler that I am using is from the Visual Studio 2005.

    Here's the error message that I receive:

    Error 2 error C2143: syntax error : missing ';' before 'SavingsAccount::{ctor}'



    Here's my code:
    class Account
    Code:
    #include "Account.h"
    
    #include <iostream>
    using std::cout;
    
    Account::Account(double total)
    {
    	if(total <= 0.0)
    	{
    		cout << "Your balance is less than or equal to zero";
    		this->balance = 0.0;
    	}
    	this->balance = total;
    }
    
    void Account::setBalance(double balanceAmount)
    {
    	this->balance = balanceAmount;
    }
    
    double Account::getBalance() const
    {
    	return this->balance;
    }
    
    double Account::credit(double add)
    {
    	double result;
    
    	result = this->balance + add;
    
    	return result;
    }
    
    bool Account::debit(double minus)
    {
    	if(minus > balance)
    	{
    		cout << "Debit amount exceeded account balance.";
    		return false;
    	}
    	balance = balance - minus;
    
    	return true;
    }
    class SavingsAccount
    Code:
    #include "SavingsAccount.h"
    
    #include <iostream>
    using std::cout
    
    SavingsAccount::SavingsAccount(double balances, double rate):Account(balances)
    {
    	this->setBalance(balances);
    	this->interest = rate;
    }
    
    void SavingsAccount::setInterest(double rates)
    {
    	this->interest = rates;
    }
    
    double SavingsAccount::getInterest()
    {
    	return this->interest;
    }
    
    double SavingsAccount::calculateInterest()
    {
    	double result;
    
    	result = this->getBalance() * this->interest;
    
    	return result;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    The error message is exactly right. See if you can figure out what it's referring to. It should have a line number to help show you the general vicinity of the problem.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    53
    It's referring to this part of the code (line 6):

    Code:
    SavingsAccount::SavingsAccount(double balances, double rate):Account(balances)

    I can't figure out what the problem is still, I rewrote it many times but I still get the same error message.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    When you get a syntax error, check for undeclared identifiers and the surrounding lines for mistakes, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    It's referring to

    Error 2 error C2143: syntax error : missing ';' before 'SavingsAccount::ctor'
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    It can mean anything, really. Syntax errors can confuse you.
    The best thing to do is look for undeclared identifiers (compiler doesn't always complain about them) and checking for mistakes, such as syntax errors on previous lines. Check for missing ; and such.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    53
    Thanks for the help, I figured out the problem:

    Code:
    using std::cout
    I forgot to put the semicolon at the end of that line of code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21