Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-12-2011, 03:41 PM   #1
LQ Newbie
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
code substitutions

GNU g++ seems to try to automatically match STL templates to patterns
in your code. E.g. if you code a swap looking function it substitutes
std::swap, is this so or am I inadvertently specifying a template ?
Old 07-13-2011, 08:19 AM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Avoid specifying "using namespace std" in your code!

Also, you can always reference functions using the :: operator. Here's an example that you can play with:
#include <algorithm>
#include <iostream>

template <typename T>
void swap(T& x, T& y)
   std::cout << "I'm on strike!" << std::endl;

int main()
   int x = 10;
   int y = 20;

   std::cout << "x = " << x << ", y = " << y << std::endl;

   std::swap(x, y);   // calls the C++ library.

   std::cout << "x = " << x << ", y = " << y << std::endl;

   ::swap(x, y);   // calls the swap() function defined above.

   std::cout << "x = " << x << ", y = " << y << std::endl;
1 members found this post helpful.
Old 07-14-2011, 06:07 PM   #3
LQ Newbie
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0

I(Loarn) was trying to get the compiler to use my code and not what it considered a match
from the template supply, What finally dawned on me, I have been away for awhile, was that
is was not necessarily using the template but since I had #included <algorithm> and was
compiling with the -E flag, it was including the entire algorithm header file in the
assembler stage of the compile.
Thanks for your assistance, please ignore the misspelling I was schooled in the progressive


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
string substitutions within a file cleopard Programming 1 09-05-2008 03:52 PM
perl- multiple substitutions on same line gnashley Programming 2 11-12-2007 08:29 AM
variables within sed substitutions? ocicat Programming 3 07-29-2007 12:17 PM
Perl: Using Vars in Substitutions cramer Programming 6 08-26-2006 12:52 PM
sed? -- making substitutions scabies Linux - Software 1 12-21-2003 11:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:35 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration