C++ :: Scope Resolution Operator?
Feb 21, 2013
I have done alot of googling for the scope resolution operator and Ive gained a bit of an understanding as to what it does i know it can distinguish between global and local variables, but I see it used to access methods/members of classes such as this example, why not just use a dot instead to access it?:
sql:: Driver *driver;
Why is the scope resolution operator being used here?
View 11 Replies
ADVERTISEMENT
Jun 14, 2013
Are there any situations to explicitly use the scope resolution operator with global scope? I can imagine a situation like:
#include <cmath>
class IntWrapper{
public:
IntWrapper& pow(char);
IntWrapper(char);
private:
int m_int;
[Code] ....
But then I would think that the writer should have used a different name, and that using the scope resolution operator in the constructor body is still pointless...
View 8 Replies
View Related
Apr 23, 2013
I have a global var (m) with an initial value 5.
I have a template class (A) that derives from a either a base class that has a member (_A1.m) or not (_A0), based upon it's template parameter. class (A) has a member function (fn) returns the value of (m) as it understands what (m) is.
However, this gives different results compared with a non-template class in a similar scenario. I'm expecting that if derived from _A1, that m should be taken from the base class scope and if derived from _A0, it should be taken from the global one.
Here is the code for your amusement:
int m = 5;
class _A0 {
public:
_A0(int) {
[Code] ....
This compiled using g++ 4.5.3 and 4.6.3 with the same results:
Global value of m is: 5
B0 class has no internal m member. Object resolves m internally with value 5
B1 class has internal m member. Object resolves m internally with value 3
A<_A0> class has no internal m member. Object resolves m internally with value 5
A<_A1> class has internal m member. Object resolves m internally with value 5
View 2 Replies
View Related
Mar 29, 2015
Just reading some code and come across a section where its setting the resolution on a screen
so like
image->sizeX=640;
image->sizeY = 480;
size = image->sizeX * image->sizeY *3;
float sizeLog = ceil(log((float)image->sizeX) / log(2.F)));
So yea, my understanding of this code is that firstly there is member access and that a resolution is being set.
And then its like 640 * 480 * 3
and then the log of 640 *480*3 ...being divided by something else and being rounded up by ceil
is this the right way to look at it?
and also what is the log(2.F) - i don't really understand that.
View 3 Replies
View Related
Jan 2, 2014
I'm trying to learn how to use variadic templates, and I decided a great example would be serializing a series of types into a stringstream:
Code:
// Send a fully constructed message.
virtual void send(ostringstream &msg) = 0;
// Construct a message from the arguments and send it.
// This is the usual entry point.
template <typename ...Args>
void send(Args ...args {
[Code] ....
This works fine, so far as I can tell. However, I decided to see if I could specialize the way certain types are serialized. I tried using a Google Protocol Buffer object as an example, and added this:
Code:
// Handle a protocol buffer type while constructing a message.
template <typename ...Args>
void send(ostringstream &msg,
const google::protobuf::MessageLite &protobuf, Args ...args) {
std::string msg_str = protobuf.SerializeAsString();
msg << msg_str;
send(msg,args...);
}
I would expect this overload to be preferred over the generic T overload when a protobuf object (which always inherits from MessageLite) is passed into send() anywhere in the list. However, this is not happening. I am getting an error message to the effect that << doesn't know how to deal with my concrete type, pointing at the T overload.
View 4 Replies
View Related
Mar 25, 2013
I have an mfc dialog of size 1280 X 1024 and when i change the resolution to 800 X 600, after adding scroll bar, it don't show the entire dialog contents, Seems like it clips the 800 X 600 portion.
I have handled VScroll and HScroll. It works fine for higher resolutions!
View 1 Replies
View Related
Dec 6, 2012
I have written a program to capture signal from machine and display it on screen in the form of sinosoidal wave. I have print buffer for 256 X 400 pixel strip chart. This prints fine if I set page size A4 and resolution 600 DPI. If anyone changes print parameters , there is problem. I can resize the printer buffer and interpolate the stored signal.
My problem is , how to find the printer resolution from GetDeviceCaps ? how to know the Print Type Normal / Draft etc in mFC.
View 2 Replies
View Related
Aug 25, 2014
What is the limit of a VGA with 256k VRAM, running 1bpp monochrome graphics? How high can the display resolution go?
View 3 Replies
View Related
Jun 13, 2014
I stumbled upon an unexpected difference between GCC and VisualStudio: Different overloaded functions are called in the following example:
// -------- can assume this is located in 'tool.h' file --------------
// Fwd declaration support foo( const int& ) gets called as expected by both compilers
// void foo( const int& n );
template< typename T >
void foo( const T& n ) {
[Code] ....
What happens: I expected that by calling bar(1) compiler will notice both versions of foo() and call the best match, in this case foo(const int&). That is not the case.
Note that overloaded foo(const int&) is below bar(). It seems that at that point GCC does not see overloaded version, and happily calls template version. Visual studio on the other hand has no problem finding them both.
If I introduce a forward declaration of foo( const int& ) before bar(), both compilers call that version correctly. Unfortunately, that is not a solution for my problem here.
Template version is part of a library while overloaded is part of the user code. Both would be located in different (header) files and I would not like to impose #include order to the users or to be dependant on it.
View 2 Replies
View Related
Mar 14, 2013
Need a free image library that can handle png xresolution and yresolution. I need it to be compatible with visual studio 6.0
View 1 Replies
View Related
Mar 22, 2013
I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.
Here's my class [In a header file "Shinigami.h"]
#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);
[Code] .....
If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.
I thought it was the namespace, but I included that.
View 9 Replies
View Related
Apr 22, 2013
Did a little Googling on this but couldn't find anything definitive. Is it safe to do something like
Code:
void MyClass::myFunc(){
my_type_t &foo = some_obj->get_member_reference();
store_for_later(&foo);
}
Then at some pointer later in execution, another function uses the pointer passed to store_for_later.
View 5 Replies
View Related
Dec 14, 2013
The situation is the following :
Code:
vector<int>& function(int a , int b){
vector<int> s(3000000);
vector<int> xxx(4);
return xxx
}
Not to board people with details but if i am returning the the reference to a vector xxx what happens to vector s. is it destroyed ?? it should be, but i don't see it on my memory map (memory is not released) . can this be or should i go and search for error on some other place.....
View 2 Replies
View Related
Mar 16, 2013
Can we use using declaration within name space scope? is it safe to use it?
I think we can use using declaration for class scope and function scope only.
View 9 Replies
View Related
Oct 9, 2013
how to solve this undeclared error when compiling this code. I assume it has something to do with scope.
C code - 47 lines - codepad
Code:
#include <stdio.h>
int main(void) {
struct bank_account {
[Code].....
View 3 Replies
View Related
Oct 29, 2014
main.cpp
#include <iostream>
#include "sushi.h"
using namespace std;
int main()
{
do {
......sushi go;
......string x; <----------------------------Declared x here
......cout << "wanna use a banana?" << endl;
[Code ....
Error reads: 'x' was not declared in this scope.
How do I fix this?
P.S The sushi class does not matter, that is all perfect. Also, the dots are to represent my tabbing to make it easier to understand.
View 2 Replies
View Related
Jan 10, 2015
For some reason my compiler says "rename not declared in this scope" .... Isn't it declared in iostream? Or is rename only for C not C++? And if it is only for C how do I rename a file in C++ then?
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]){
char oldname[] = "RomeTW.exe";
[Code] .....
View 2 Replies
View Related
Jul 2, 2012
I have c# code something like below.
void ExecuteSomething() {
TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
transactionOptions.Timeout = TimeSpan.FromSeconds(TransactionTimeOutInSeconds);
[Code] ....
I am retrieving the data by using above code
From some other code i am calling some function in c# through windows service. That function is going to delete some unwanted data from sql server database. if i wanted i initiate the request it will take 30 min to delete the data.
in this 30 min time i am unable to access other pages in my website. is there any better way to design this?
View 2 Replies
View Related
Mar 1, 2014
i am writing this bank accounts program using structures. i haven't implemented the function before that i want to check if the data is being read and printed. When i build and run the program in visual studio it gives me the following error. "No constructor could take the source type, or constructor overload resolution was ambiguous". Now whats wrong in this program?
/* Bank Accounts Program */
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>//needed to use system() function
using namespace std;
const int MAX_NUM = 50;
struct Name{
[code]....
View 1 Replies
View Related
Jan 31, 2014
Ran into something today that does not make sense:
This compiles: Code: int x = 5;
switch(x) {
case 0:
{
int value = 5;
}
break;
[Code] ....
Ok so it doesn't like int value = 6 b/c of int value = 5 for case 0. However since the value in case 0 is declared within the brackets one would think it has case scope.
So I tried this:
Code: int x = 5;
switch(x) {
case 0:
{
int value = 5;
}
break;
[Code] ....
Now it doesn't like it b/c value has not been declared in case 1:. These two conditions cannot possibly be both true at the same time. You cannot disallow the declaration of value in case 1 b/c it interferes with value in case 0 and at the same time disallow me to use value from case 0 b/c it is not in scope. If it was not in scope then theoretically I should be able to declare value in case 1.
Both MSVS 2012 and 2013 exhibit the same behavior. I checked the standard and it is unclear on the matter.
View 7 Replies
View Related
Dec 16, 2013
Is it's scope confined to that single case?
char ch;
switch(ch) {
case '1':
using namespace common::section1; //only this case??
break;
[Code] ....
View 8 Replies
View Related
Oct 11, 2014
I'm trying out friend functions not in just one source file to see how it works but I'm getting an error.
/* ----- ClassOne.h ----- */
#ifndef CLASSONE_H_
#define CLASSONE_H_
#include "classTwo.h"
using namespace std;
class ClassOne {
[Code] ....
Basically, I just want to print out the private members of ClassOne using ClassTwo's friend function twoPrintsOne().
The error is in classTwo.cpp and it says that m_a and m_b in the twoPrintsOne function are not declared in this scope.
View 3 Replies
View Related
Dec 11, 2013
I have observed that inline functions can not be prototyped. example:
.cpp file:
inline void whatever() {
cout<< "this is inline"<< endl;
}
.h file, prototype
inline void whatever(); //would ask for a definition
Because of this, I have have just made functions that are used in only 1 .cpp file (ever) inlined, to make it more efficient (and it has demonstrated that it is more efficient). It's worked out fine so far, but what about the scope of the definition??
Since an inline function is like a templated function, in that it can't be prototyped, how are name conflicts resolved, and what is the best practice for writing inline functions??
Example of a conflict:
//in some arbitrary header...
void do_somthing();
//in .cpp file that inlcudes the header...
inline void do_somthing() {
cout<< "I'm doing somthing!!"<< endl;
} int main() {
do_somthing(); //which one?? it compiles fine though!!
return 0;
}
View 2 Replies
View Related
May 20, 2013
I have this error - [Error] 'fprintf' was not declared in this scope (line 32)
and this - [Error] 'fclose' was not declared in this scope (line 33)
here's my code.........
1 #include <iostream>
2 using namespace std;
3 #include <windows.h>
4 #include <winuser.h>
5
6 int save (int key_stroke, char *file);
[Code] ......
View 3 Replies
View Related
Jan 27, 2014
I'm working through this neural network tutorial, unfortunately I get stuck trying to compile on line 28, saying "error: 'neuronNum' not declared in this scope." I seem to always get stuck on these kinds of errors, yet I don't understand because I though that the variable was declared and initialized within the for loop.
#include <iostream>
#include <vector>
using namespace std;
[Code]....
View 5 Replies
View Related
Jan 28, 2014
I'm trying to make a dynamic 2d array of a Tile Object I created, the Dynamic 2d array was working when I tested it as an int array but not that I gave it a type of Tile it is giving me the above error. I'm reading values from a .txt .
tile Tile;
Tile **grid;
grid = new Tile*[a];
for (int i = 0; i < a; ++i) {
grid[i] = new Tile[b];
}
View 9 Replies
View Related