![]() |
|
#1
|
|||
|
|||
error: expected primary-expression before '.' tokenCould someone tell me what the error message "error: expected primary-expression before '.' token" means, or at least what I'm doing wrong?
Here's the code: CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Some irrelevant code such as other functions in class database have been omitted. Also: hi, everyone! Last edited by LuciWiz : 18-Feb-2006 at 10:43.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|||
|
#2
|
||||
|
||||
Re: error: expected primary-expression before '.' tokenHi Mist,
Welcome to the GID Forums. The problem is that you have not created an instance of the class, or to be simple, you have not created a variable of the type database. Class can be simply defined as a user defined datatype, for example, similar to string. How do you declare a string? string str; Then you can access the string functions such as length etc isnt it? Similarly, create a new variable of type database like this: database db; Then, you can access the member function like this: db.createSessionfile(); Also instead of [code] and [/code] you can use [c++] and [/c++] tags. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: error: expected primary-expression before '.' tokenOh, it's so obvious now that you mention it! Thanks for the quick reply aswell!
I have probably made some equally silly mistake, for now I'm getting multiple definition errors for every single function. The only change is in main.cpp: CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: error: expected primary-expression before '.' tokenHey! I know this is off topic but everytime i see one of your posts with C/C++ code, I see you always use
CPP / C++ / C Code:
What is this for? Thanks in advance, 5had0w |
|
#5
|
||||
|
||||
Re: error: expected primary-expression before '.' tokenQuote:
Multiple definition errors are caused due to multiple inclusion of the header files. For example, consider that your class is in database.h You create another file algorithm.h where you include the database.h file. Again in your main.cpp file, you include both database.h and algorithm.h. What happens now? You include the file database.h two times!!! How to avoid this problem? Use conditional compile statements #ifndef, #define and #endif. For example, you can do like this: CPP / C++ / C Code:
Now what happens? The first time you try to include the database.h file, _DATABASE_ is not defined. So it is defined now, and the class definition is included. The next time you try to include the database.h file, _DATABASE_ is already defined, and the code is not included. This prevents redefinition errors. Hope i explained it clear. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#6
|
||||
|
||||
Re: error: expected primary-expression before '.' tokenQuote:
You can find more information here: Namespaces Inside the namespace std, there are various classes, and members. For example, cin, cout, endl are inside the namespace std; In order to use them, you should specify in which namespace they are present. Either you can write like this: using namespace std; and use cin or cout, etc. Or you could prefix the namespace with scope resolution operator like this: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#7
|
|||
|
|||
Re: error: expected primary-expression before '.' tokenThanks!
I've been always using since I started programming this way: CPP / C++ / C Code:
and it works but I think I need to change... Thanks again! Cumps |
|
#8
|
||||
|
||||
Re: error: expected primary-expression before '.' tokenQuote:
But the standards have changed, and you should only use: #include<iostream> (This file defines the std namespace.) and NOT like this: #include<iostream.h> The last one is deprecated, and is not defined inside a namespace. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#9
|
|||
|
|||
Re: error: expected primary-expression before '.' tokenOh ok! Thanks dude
And sorry for off topic. Cumps |
|
#10
|
|||
|
|||
Re: error: expected primary-expression before '.' tokenQuote:
Quote:
I was actually really careful about only including files once Quote:
I did this with all my headers, but the problem remains! I even tried doing the same thing with the cpp-files aswell, but no change. |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with enums and function program | rho | C++ Forum | 8 | 27-Jun-2005 20:13 |
| Replacing N'th token in a file. | kobi_hikri | C Programming Language | 2 | 24-Jun-2005 03:00 |
| Can enum have same name as class? | crystalattice | C++ Forum | 3 | 08-Dec-2004 17:43 |
| Floating point exception error (Note-long post) | crystalattice | C++ Forum | 16 | 11-Sep-2004 08:37 |
| storing a token pointer as a string | CoreLEx | C Programming Language | 1 | 07-Oct-2003 12:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The