Jump to content

random c++ error


Recommended Posts

having a bit of an issue with getting this to compile, specifically because of this error

[spoiler=code]

// Program file: ratdrive.cpp

#include <iostream>
#include <iomanip>
#include <cstdlib>

#include "rational.h"

using namespace.std;

int main() // testing rational class
{
    rational r1, r2, r3, r4;

    cout << "Enter the first number (<integer>/<integer>): ";
    cin >> r1;
    cout << "Enter the second number (<integer>/<integer>): ";
    cin >> r2;
    cout << "Enter the third number (<integer>/<integer>): ";
    cin >> r3;

    r4 = r1 + r2 + r3; // test sum
    cout << "The sum of your three numbers is " << r4 << endl;

    return 0;
}

[spoiler=error]

Line 9

error: expected identifier before '.' token

error: expected ';' before '.' token

error: expected unqualified-id before '.' token

any help? this is the client code, as far as I know, the other files are 100% fine(I can post them if someone wants to look at them)

Link to comment
Share on other sites

using namespace.std;
should be

using namespace std;
Also, using declarations are bad practice unless you really need them. Especially for whole namespaces. A better approach would be

using std::cout;
using std::cin;
or better yet, just every time you have a cout, just do std::cout

imo, and iirc, ofc

Link to comment
Share on other sites

oh damn it why do i have a period there

thanks

and i'll keep that in mind, thanks

It's mostly just to learn good habits for when you have to include your files and are planning on using multiple namespaces. If one of your includes declares a namespace, but you forget, and then your main tries to do other namespace stuff, well, it can get messy. At least that's how I remember it being explained.
Link to comment
Share on other sites

or better yet, just every time you have a cout, just do std::cout

this, so much

god I hate when people import * from foo in python or this C++ equivalent. Run it through an obfuscator and hit me over the head with a heavy book ffs, it's the same thing.

Link to comment
Share on other sites

import sys

from sys import *

It's actually harder to do it the wrong way than it is to do it the correct way. Or something. Basically, if you're using the re module and you're calling static members of re without prepending them with "re." then you're doing it wrong.

Of course a lot of people would say "if you're using the re module you're already doing it wrong" because "if you use regular expressions to solve a problem you now have two problems", but to that I say "you're bad at regular expressions and should be ashamed".

Edited by Amorphous Laugh
Link to comment
Share on other sites

I could do what Bal did and try to cite why, or even give a very real example of where it's bit me in the ass to do it the wrong way or put up with other people doing it the wrong way, but...suffice to say, there's a "right way" for a good reason. It's not some elitist crap to pick on people who don't do it the right way.

Link to comment
Share on other sites

I could do what Bal did and try to cite why, or even give a very real example of where it's bit me in the ass to do it the wrong way or put up with other people doing it the wrong way, but...suffice to say, there's a "right way" for a good reason. It's not some elitist crap to pick on people who don't do it the right way.

There is nothing wrong with telling people how to do things the "right way". Particularly when it makes things less cluttered/confusing, more efficient or just readable.

Link to comment
Share on other sites

There is a problem with doing stuff just because you're told without at least wondering why, though, and it falls on the person dictating what is to be done to provide that explanation, at least upon request. The best I care to go into at the moment though is just that it will definitely hurt you (probably physically, if your head ache gets bad enough) if you go around using stuff in a module without using full qualification of the entity being utilized. You could end up with a situation where you have to analyze every line using similarly spelled symbols in every source file of your project, which is pretty terrible even for projects with single source files.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...